error in calling soap function in php - php

how can i get soap data in php from this site
http://www2.rlcarriers.com/freight/shipping-resources/rate-quote-instructions
they have "GetRateQuote(string APIKey, RequestObjects.RateQuoteRequest request)"
this function how can i call this from php soap
$client = new SoapClient('http://api.rlcarriers.com/1.0.1/RateQuoteService.asmx?WSDL');
//print_r($client);
//$result = $client->GetRateQuote('xxxxxxxxxxxxxxxxxxxxxx.......',);
print_r($result);
?>
what should i have to pass in second parameter

Try the following:
$client = new SoapClient("http://api.rlcarriers.com/1.0.1/ShipmentTracingService.asmx?WSDL", array("trace" => 1));
$request = array(
"APIKey" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"request" => array(
"TraceNumbers" => array(
0 => "xxxxxxxxx"
),
"TraceType" => "PRO",
"FormatResults" => "true",
"IncludeBlind" => "true",
"OutputFormat" => "Standard"
)
);
try {
$response = $client->TraceShipment($request);
print_r($response);
}
catch (SoapFault $exception) {
print_r($exception);
}

Related

How can I use SoapClient in my Php Programm

How can I use the SoapClient with the method "sites_web_domain_add" to interact with the ispconfig api? My Code produces a folowing error:
error
Also soap client/server is set to enabled.
If i execute the code in my terminal it just works fine but not in my controller, so have I missed something? Like importing the right soap?
Thanks for helping!
$username = 'apiuser';
$password = '1234';
$soap_location = 'https://localhost:8080/remote/index.php';
$soap_uri = 'https://localhost:8080/remote/';
$context = stream_context_create(
[
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
]
]
);
$client = new SoapClient(
null,
[
'location' => $soap_location,
'uri' => $soap_uri,
'trace' => 1,
'exceptions' => 1,
'stream_context' => $context
]
);
try {
if ($session_id = $client->login($username, $password)) {
echo "Login successful. Session ID: $session_id<br>";
}
//* Set the function parameters.
$client_id = 1;
$params = [
'server_id' => 1,
'ip_address' => '*',
'domain' => 'test2.int',
'type' => 'vhost', // vhost | alias | vhostalias | subdomain | vhostsubdomain
];
$client->sites_web_domain_add($session_id, $client_id, $params, $readonly = false);
if ($client->logout($session_id)) {
echo "Logged out.<br>";
}
} catch (SoapFault $e) {
echo $client->__getLastResponse();
die("SOAP Error: {$e->getMessage()}");
}

HTTP Guzzle not returning all data

I have created a function that contacts a remote API using Guzzle but I cannot get it to return all of the data available.
I call the function here:
$arr = array(
'skip' => 0,
'take' => 1000,
);
$sims = api_request('sims', $arr);
And here is the function, where I have tried the following in my $response variable
json_decode($x->getBody(), true)
json_decode($x->getBody()->getContents(), true)
But neither has shown any more records. It returns 10 records, and I know there are over 51 available that it should be returning.
use GuzzleHttp\Client;
function api_request($url, $vars = array(), $type = 'GET') {
$username = '***';
$password = '***';
//use GuzzleHttp\Client;
$client = new Client([
'auth' => [$username, $password],
]);
$auth_header = 'Basic '.$username.':'.$password;
$headers = ['Authorization' => $auth_header, 'Content-Type' => 'application/json'];
$json_data = json_encode($vars);
$end_point = 'https://simportal-api.azurewebsites.net/api/v1/';
try {
$x = $client->request($type, $end_point.$url, ['headers' => $headers, 'body' => $json_data]);
$response = array(
'success' => true,
'response' => // SEE ABOVE //
);
} catch (GuzzleHttp\Exception\ClientException $e) {
$response = array(
'success' => false,
'errors' => json_decode($e->getResponse()->getBody(true)),
);
}
return $response;
}
By reading the documentation on https://simportal-api.azurewebsites.net/Help/Api/GET-api-v1-sims_search_skip_take I assume that the server is not accepting your parameters in the body of that GET request and assuming the default of 10, as it is normal in many applications, get requests tend to only use query string parameters.
In that function I'd try to change it in order to send a body in case of a POST/PUT/PATCH request, and a "query" without json_encode in case of a GET/DELETE request. Example from guzzle documentation:
$client->request('GET', 'http://httpbin.org', [
'query' => ['foo' => 'bar']
]);
Source: https://docs.guzzlephp.org/en/stable/quickstart.html#query-string-parameters

PHP SoapClient Cannot process the message because the content type 'text/xml;

I cannot connect to webservice and send/receive data
Error
HTTP,Cannot process the message because the content type 'text/xml;
charset=utf-8' was not the expected type 'application/soap+xml;
charset=utf-8'.
Code
$parameters = [
'UserName' => 12324,
'Password' => 432123,
'Bill_Id' => 153585611140,
'Payment_Id' => 8560103,
];
$url="https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";
$method = "VerifyBillPaymentWithAddData";
$client = new SoapClient($url);
try{
$info = $client->__call($method, array($parameters));
}catch (SoapFault $fault){
die($fault->faultcode.','.$fault->faultstring);
}
Notice : not work Soap version 1,1 and other resolve sample for this error in stackoverflow.
You could try
$url = "https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";
try {
$client = new SoapClient($url, [
"soap_version" => SOAP_1_2, // SOAP_1_1
'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
'trace' => 1,
'exception' => 1,
'keep_alive' => false,
'connection_timeout' => 500000
]);
print_r($client->__getFunctions());
} catch (SOAPFault $f) {
error_log('ERROR => '.$f);
}
to verify that your method name is correct.
There you can see the method
VerifyBillPaymentWithAddDataResponse VerifyBillPaymentWithAddData(VerifyBillPaymentWithAddData $parameters)
Next is to check the Type VerifyBillPaymentWithAddData and if the parameter can be an array.
Also you could test to call the method via
$client->VerifyBillPaymentWithAddData([
'UserName' => 12324,
'Password' => 432123,
'Bill_Id' => 153585611140,
'Payment_Id' => 8560103,
]);
or yours except the additional array
$info = $client->__call($method, $parameters);
EDIT:
Assuming to https://stackoverflow.com/a/5409465/1152471 the error could be on the server side, because the server sends an header back that is not compatible with SOAP 1.2 standard.
Maybe you have to use an third party library or even simple sockets to get it working.
Just use the following function. Have fun!
function WebServices($function, $parameters){
$username = '***';
$password = '***';
$url = "http://*.*.*.*/*/*/*WebService.svc?wsdl";
$service_url = 'http://*.*.*.*/*/*/*WebService.svc';
$client = new SoapClient($url, [
"soap_version" => SOAP_1_2,
"UserName"=>$username,
"Password"=>$password,
"SOAPAction"=>"http://tempuri.org/I*WebService/$function",
'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
'trace' => 1,
'exception' => 1,
'keep_alive' => false,
'connection_timeout' => 500000
]);
$action = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', "http://tempuri.org/I*WebService/$function");
$to = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', $service_url);
$client->__setSoapHeaders([$action, $to]);
try{
return $client->__call($function, $parameters);
} catch(SoapFault $e){
return $e->getMessage();
}
}

Object of class GuzzleHttp\Psr7\Request could not be converted to string

I've got an issue for laravel 5.4 when I trying to using guzzleHttp. here is my code.
use GuzzleHttp\Client;
$url = 'http://example.com';
$client = new Client();
$parameter = ['query' => ['name' => 'xxx', 'address' => 'yyy'], 'headers' => [ 'User-Agent' => 'xxxx', 'exceptions' => false, 'timeout' => 10 ]];
$res = $client->request('GET', $url, $parameter);
if ($res->getStatusCode() == 200)
{
$json = (string)$res->getBody();
return $json;
}
and I've got this error on log:
Error Exception: Object of class GuzzleHttp\Psr7\Request could not be converted to string
what is wrong with my code? please kindly help me.
fyi, this error not always happen. sometimes it show this error, sometimes success.
thank you
$json = $res->getBody()->getContents();
try this
Try this.....
try {
$parameter = ['query' => ['name' => 'xxx', 'address' => 'yyy'], 'headers' => [ 'User-Agent' => 'xxxx', 'exceptions' => false, 'timeout' => 10 ]];
$res = $client->request('GET', $url, $parameter);
if ($res->getStatusCode() == 200)
{
return $res->getBody()->getContents();
}
}catch(Exception $e){
echo 'Caught exception: ', $e->getMessage();
}
$response = $client->post('http:yanjye.com3', ['phone' => '00','password' => '5555',]);
if ($response->getStatusCode() == 200){
$json = (string)$response->getBody();
return $json;
}
var_dump( $response);
die();
Hello, brother, I think this is the Good way to which is Working On both laravel 5.2[larave 5.2]
i have removed Httm
[laraver 5.2][1]
and use this code :
[1]: https://laravel.com/docs/7.x/http-client`

PHP SoapClient unable to access webservice using proxy

Using SoapClient in PHP, I've come across a problem I have not been able to find a solution to.
I'm using a local copy of the wsdl file and I am using this setup:
$this->client = new \SoapClient(__DIR__ . '/../../some.wsdl',
array(
'proxy_host' => $ip,
'proxy_port' => $port,
'trace' => 1,
'exceptions' => true,
'cache_wsdl' => WSDL_CACHE_NONE
)
);
This gives error : "Forbidden" when calling :
$this->client->__call($method, $params)
I have tried calling __getFunctions()
$this->client->__getFunctions()
that gives the list of all function in my WSDL file.
Am I missing something?
Debug code with like this :
<?php
try{
$client = new SoapClient($wsdl, $params);
$out = $client;
}catch(Exception $e){
$out = array('error' => $e, 'libxml' => libxml_get_last_error());
}catch(SoapFault $s){
$out = array('error' => $s, 'libxml' => libxml_get_last_error());
}
var_dump($out);
exit();

Categories