NuSOAP 0.7.2 sending empty SOAP requests - php

OK, so before I get flooded with answers like "Use PHP's built-in SOAP extension" or "upgrade to nuSOAP 0.9.5" I just want to make it clear that these are not an option in my situation. I'm working in a hosted environment and I'm lucky they even had this legacy version of nuSOAP installed on the server.
That said, I need some help with my SOAP requests.
Here's what I have so far:
require_once('nusoap_0.7.2/nusoap.php');
ini_set("soap.wsdl_cache_enabled", "0");
date_default_timezone_set('America/Los_Angeles');
$wsdl = "https://api.bronto.com/v4?wsdl";
$ns = "https://api.bronto.com/v4";
$client = new soapclient($wsdl, array('trace'=>1, 'encoding'=>'UTF-8'));
// Login
$token = "API-TOKEN";
$sessionId = $client->call('login', array('apiToken' => $token), $ns, $ns);
if (!$sessionId) {
print "Login failed.\n";
exit;
}
print_r($sessionId);
$client->setHeaders(array($ns, 'sessionHeader', array('sessionId' => $sessionId)));
echo htmlspecialchars($client->request, ENT_QUOTES); // debug request
This is what the login call to the API returns:
Array ( [faultcode] => soap:Client [faultstring] => 107: There was an error in your soap request. Please examine the request and try again. [detail] => There was an error in your soap request. Please examine the request and try again. )
This is what the SOAP request ends up looking like:
POST /v4 HTTP/1.0 Host: api.bronto.com User-Agent: NuSOAP/0.7.2 (1.94)
Content-Type: text/xml; charset=UTF-8
SOAPAction: ""
Content-Length: 379
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns7166="https://api.bronto.com/v4">
<SOAP-ENV:Body>
<parameters/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The SOAP request appears to be sending fine but the envelope is empty. I suspect I may need to replace the arrays in the request with SoapVal objects, but the documentation on this object is difficult to get my head around.
For reference, this is the PHP SOAP code I am trying to translate to nusoap 0.7.2
ini_set("soap.wsdl_cache_enabled", "0");
date_default_timezone_set('America/New_York');
$wsdl = "https://api.bronto.com/v4?wsdl";
$url = "https://api.bronto.com/v4";
$client = new SoapClient($wsdl, array('trace' => 1, 'encoding' => 'UTF-8'));
$client->__setLocation($url);
// Login
$token = "ADD YOUR API TOKEN HERE";
$sessionId = $client->login(array("apiToken" => $token))->return;
if (!$sessionId) {
print "Login failed.\n";
exit;
}
$client->__setSoapHeaders(array(new SoapHeader("http://api.bronto.com/v4", 'sessionHeader', array('sessionId' => $sessionId))));
print "Login was successful.\n";

I had had same problem even on NuSOAP/0.9.11 and later. ;-) SOAPAction: ""
NuSOAP has several issues. E.g. it supports only wsdl-mode for me, and your NuSOAP api usage is wrong (new nusoap_client second parameter).
For using wsdl-mode you must smth like this:
$wsdlurl = 'https://api-sandbox.direct.yandex.com/v5/campaigns?wsdl'; // your wsdl url
$token = '<your token if needed>';
$locale = 'en';
// Construct NuSOAP-client
$client = new nusoap_client($wsdlurl, 'wsdl'); // second parameter must be boolean true or 'wsdl'
# Auth of NuSOAP-client
$client->authtype = 'basic'; /// but Yandex Direct needs 'bearer'
$client->decode_utf8 = 0;
$client->soap_defencoding = 'UTF-8';
// ..... $client->setCredentials and $client->setHeaders if needed
// Call soap/wsdl api method
$result = $client->call(
'get',
array('SelectionCriteria' => (object) array(), 'FieldNames' => array('Id', 'Name'))
); // string $operation (required), mixed $params (required), string $namespace (optional method namespace for non-WSDL), string $soapAction (optional SOAPAction value for non-WSDL)
// Output
echo "Request:<pre>".htmlspecialchars($client->request, ENT_QUOTES)."</pre>";
echo "Response:<p>".nl2br(htmlspecialchars($client->response, ENT_QUOTES))."</p>";
// Debug
echo '<hr><pre>'.htmlspecialchars($client->debug_str, ENT_QUOTES).'</pre>';
P.S.: If you need Yandex, fixed lib is here and samples client4yandex.

Related

SOAP XML Request with Basic Authentication in PHP

I am trying to setup a SOAP request in PHP using HTTP basic Authentication. For some reason I keep getting, HTTP/1.1 401 Unauthorized error.
This is an example of the request I'm trying to create:
POST https://url/someurl/soap HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "SomeSoapAction"
User-Agent: SomeUser Client-HttpClient/3.1
Content-Length: 1503
Authorization: Basic dGsomebasicreyteryheyp0ZXN0ZXI=
Host: somehost.com
This is a snippet of my code:
ini_set('display_errors',1);
ini_set("soap.wsdl_cache_enabled", "0");
error_reporting(E_ALL);
$wsdl = "urltosomewsdlfile.wsdl";
$url = "somerl";
$username = "username";
$password = "password";
$encodedstuff = base64_encode("{$username}:{$password}");
$client = new SoapClient($wsdl, array('exceptions' => true,'trace' => true,'login' => 'somelogin', 'password' => 'somepw'));
$header = new SoapHeader($url, 'Authorization: Basic', $encodedstuff);
$client->__setSoapHeaders($header);
try {
$result = $client->SomeSoapAction();
} catch (SoapFault $soapFault) {
var_dump($soapFault);
echo "<br />Request :<br />", htmlentities($client->__getLastRequest()), "<br />";
echo "<br />Response :<br />", htmlentities($client->__getLastResponse()), "<br />";
}
If I take the username and password out of the new SoapClient section it throws up Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from...
If I put in the base64 encoded variable to the new SoapClient section instead of the username/pw it throws the same Parsing error as above:
$client = new SoapClient($wsdl, array( 'authentication' => "Basic $encodedstuff", 'exceptions' => true,'trace' => true,));
The username and password work when loading the URL directly.
Can anyone point me in the right direction? Thanks for any help.
Update 12/18/18: I've been trying this as a new method suggested, but still receive the same 401 error message:
$opts = array( 'http'=>array( 'method'=>"POST", 'header' => "Authorization: Basic " . base64_encode("{$user}:{$pw}") ) );
$context = stream_context_create($opts);
$client = new SoapClient($wsdl, array('stream_context' => $context,'exceptions' => true,'trace' => true,));
$header = new SoapHeader($url, 'Authorization: Basic', $encodedstuff);
$client->__setSoapHeaders($header);
Update 15/01/19:
I'm still having issues with this.
Using SOAPUI I can make a successful request and gain authentication. I can't see what the difference is between the SOAPUI request and my own PHP request.
I've noticed that the request header created by my PHP code alters the POST and Host endpoint URLs. The first part of the POST URL has the domain removed and the Host also has the first section of the URL removed.
SOAPUI request header (correct returns 200):
POST https://test-example.com/file/SOAP HTTP/1.1
Host: test-example.com
PHP request header (returns a 401):
POST /file/SOAP HTTP/1.1
Host: example.com
This seems to be causing the problem as it looks as if I'm pointing to the wrong endpoint. Does anyone have any advice on what might be wrong with my PHP code to break this request? Thanks.

How to set content type to 'application/soap+xml; charset=utf-8' in PHP while SOAP request

When I try to send a request to the WSDL I got this error Cannot process the message because the content type text/xml; charset=utf-8 was not the expected type application/soap+xml; charset=utf-8
Here is my code
$client = new SoapClient("http://bsestarmfdemo.bseindia.com/MFOrderEntry/MFOrder.svc?singleWsdl");
$parameter = array(
'User ID' => '0123',
'Password' => 'mf#abc',
'Pass Key' => 'abcdef1234',
);
$result = $client->getPassword($parameter);
I tried passing content type like this
$client = new SoapClient("http://bsestarmfdemo.bseindia.com/MFOrderEntry/MFOrder.svc?wsdl",array('content type'=>'application/soap+xml'));
but didnot work.
Here is the WSDL Link :WSDL Source Link
Please share some solutions. Thanks in advance.
Just change the SOAP version in your request to 1.2
$client = new SoapClient("http://bsestarmfdemo.bseindia.com/MFOrderEntry/MFOrder.svc?wsdl",array('soap_version' => SOAP_1_2));

PHP SoapClient can not handle redirect to https

I'm implementing a SOAP client with PHP SoapClient.
The wsdl-file specifies URL for a function of type http (like http://api.example.com/a/b).
However, when called, I get a response
HTTP/1.0 301 Moved Permanently
Location: https://api...
Apparently the SoapClient can not handle the redirect.
How can I solve the issue?
$param = array('user' => 'Gopal',
'password' => 'Rathod',
'KeyCode' => 'XYXXYGOPALASDADXXX',
'ExternalID' => 'PUBLICSTORAGE',
'sXml' => $strinXML, 'trace' => TRUE);
$soapClient = new SoapClient('https://wsdlfullUrl.asmx?WSDL', array('trace' => TRUE));
$result = $soapClient->__soapCall('Request', array($param));
echo '<br> 3. Call Request:<br>' . $soapClient->__getLastRequest() ;
echo '<br> 4. RESPONSE:<br>' . $soapClient->__getLastResponse();
More link http://php.net/manual/en/book.soap.php

HTTP Error: cURL ERROR: 35: Unknown SSL protocol error in connection nusoap in cakephp

I am try to fetch from soap webservice which's url is like https://something.com/webservice.asmx
I tried by setting value of CURLOPT_SSLVERSION to 3 and CURLOPT_SSL_VERIFYPEER => FALSE but it didn't worked.
Php version : 5.5.12
Apache : 2.4.9 using wamp server 2
I tried to access https://api.authorize.net/soap/v1/Service.asmx
and my code is working for this webservice but not for another webservice
my code looks like this
$client = new nusoap_client($wsdl);
$client->soap_defencoding = 'utf-8';
$mysoapmsg ='somexml';
$response = $client->send($mysoapmsg, $soapaction);
You need to put in the details about the other web service; this is very vague. A normal web service call should look like this:
$client = new SoapClient("http://domain.com/wservices.asmx?wsdl", array('login' => "USERNAME",
'password' => "PASSWORD"));
$param = array("param_name" => $param_value);
$response = $client->__call("MethodName", array("parameters" => $param));
echo "<pre>";
print_r($response);
echo "</pre>";

Implement an Air API by sending a SOAP request

I have a php web site. Here I need to implement air ticket searching and booking functionality. In order to do this, I have used a paid API from ARZOO web site... I got all the documentation from ARZOO. I have read the entire doc. The Doc Says
"Accessing this service requires standard SOAP client. SOAP client should authenticate
itself through user name and password. Client should get their IPs registered with
Arzoo and get a user account created. The Arzoo web service provides a service
point URL. Web service clients should post SOAP request message as an attachment
for the desired response. The XML structure of different web services is discussed in
the respective documents."
You can connect to Arzoo XML services with the following test service point URLs:-
FlightAvailability:http://<url>/DOMFlightAvailability?wsdl
I think need to send the request via soap is it?
But in the air availability contains
Example Request Xml
<Request>
<Origin>BOM</Origin>
.............
.............
</Request>
I have used the following code
$post_string.="<Request>";
$post_string.="<Origin>$from</Origin><Destination>$to</Destination>";
........
......
$post_string.="</Request>";
$path = ":http://<url>/DOMFlightAvailability?wsdl";
$ch = curl_init($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); //Send the data to the file
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$val = curl_exec($ch);
$headers = curl_getinfo($ch);
$errr=curl_error($ch);
But it's not giving any result.
The documents says
RESPONSE XML:-
The response will be in <arzoo_response> </arzoo_response>. This contains the Request
also.
I don't know SOAP.
I am totally disappointed. Please Help me.
I think I will get an xml response after posting the request. But how I will post my data?
Please reply
Many thanks, if anyone help me, its great appreciable
i also getting error while using SOAP CLIENT but when i use nusoap then they give me result..using this code if u get error like ip/password mismatch then You will call arzoo to verify your clientid and clientpassword
<?php
ini_set('max_execution_time','180');
include 'lib/nusoap.php';
$location_URL ='http://avail.flight.arzoo.com';
$action_URL ='http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl';
$Request = '<Request>
<Origin>BOM</Origin>
<Destination>DEL</Destination>
<DepartDate>2017-02-02</DepartDate>
<ReturnDate>2017-02-02</ReturnDate>
<AdultPax>1</AdultPax>
<ChildPax>0</ChildPax>
<InfantPax>0</InfantPax>
<Currency>INR</Currency>
<Clientid>Given by Arzoo.com</Clientid>
<Clientpassword>Given by Arzoo.com</Clientpassword>
<Clienttype>ArzooFWS1.1</Clienttype>
<Preferredclass>E</Preferredclass>
<mode>ONE</mode>
<PreferredAirline>AI</PreferredAirline>
</Request>';
$clientinfo = array('soap_version'=>SOAP_1_1,
'location' =>$location_URL,
'uri' =>$action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
);
$client = new nusoap_client('http://demo.arzoo.com/ArzooWS/services/DOMFlightAvailability?wsdl', $clientinfo);
//print_r($client);
$result = $client->call('getAvailability', array($Request));
echo"<pre>";
print_r($result);
$clientInfo =simplexml_load_string(utf8_encode($result));
$flight = $clientInfo->Response__Depart->OriginDestinationOptions->OriginDestinationOption;
$error =$clientInfo->error__tag;
//echo $error;
var_dump($flight);
//exit;
//echo"<pre>";
//print_r($result);
//ECHO $error;
?>
Since they are mentioned standard SOAP client and you are sending the cURL request to the Server that will never give any response.
$location_URL = "http://xx.xxx.xx.xxx/ArzooWS/services/DOMFlightAvailability";
$action_URL ="http://com.arzoo.flight.avail";
$client = new SoapClient('http://xx.xxx.xx.xxx/ArzooWS/services/DOMFlightAvailability?wsdl', array(
'soap_version' => SOAP_1_1,
'location' => $location_URL,
'uri' => $action_URL,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'trace' => 1,
));
try
{
$result = $client->__call('getAvailability',array($req_int));
$response= htmlentities($result);
}
You can use SOAP1.1 Request.

Categories