Отправка soap curl php

Send SOAP request using CURL

I am sending a soap request using PHP curl(). I need to print my request, so that I can have a look into my request and understand weather it is going in a right format. Here is my code:

$parameters = "     //.  "; $url='//URL to the service'; $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl,CURLOPT_ENCODING,'utf-8'); curl_setopt($curl,CURLOPT_HTTPHEADER,array ( 'SOAPAction:""', 'Content-Type: text/xml; charset=utf-8', )); curl_setopt ($curl, CURLOPT_POST, 1); curl_setopt ($curl, CURLOPT_POSTFIELDS, $parameters); $result = curl_exec($curl); 

I get a wrong data sent error from the API side which means I am not sending a correct format. Can anyone please let me know how to do that? Update: Verbose information

* About to connect() to 10.2.250.4 port 9081 (#0) * Trying 10.2.250.4. * connected * Connected to 10.2.250.4 (10.2.250.4) port 9081 (#0) > POST /CoreWeb/ApplicationBusinessFacadeService HTTP/1.1 Host: 10.2.250.4:9081 Accept: */* Accept-Encoding: utf-8 SOAPAction:"" Content-Type: text/xml; charset=utf-8 Content-Length: 1087 Expect: 100-continue < HTTP/1.1 100 Continue < Content-Length: 0 < Date: Thu, 20 Mar 2014 14:04:19 GMT < Server: WebSphere Application Server/7.0 < HTTP/1.1 200 OK < Date: Thu, 20 Mar 2014 14:04:19 GMT < Server: WebSphere Application Server/7.0 < Content-Type: text/xml; charset=utf-8 < Content-Language: en-US < Content-Length: 914 < * Connection #0 to host 10.2.250.4 left intact 

Why not use PHP's SoapClient? Also it's impossible to say what the correct format should be without knowing the specific details of the specific SOAP call you're trying to make.

because I want the generated XML in a format that is different than the one that SOAP/Nusoap client gives to me

Читайте также:  Ddmlib java io ioexception

Источник

Sending a SOAP Request with Query String & POST Data in PHP using CURL

I am trying to obtain a report from a website which actually has a login mechanism in it. So Far I have been able to do it and preserve the cookie in a file.

 $url = 'https:///action/method/blah'; $options = array( 'textUsername' => 'alpha', 'textPassword' => 'beta', 'appId' => 'gama', 'browser' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:41.0) Gecko/20100101 Firefox/41.0' ); $cookie_file = APPPATH.'cookies/cookie.txt'; $postdata = http_build_query($options); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, $options['browser']); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt( $ch, CURLOPT_COOKIESESSION, true ); curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie_file ); curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookie_file ); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); echo $result; curl_close($ch); 

Now I want to extend this to fetch the report, I intercepted the original request in firefox and It looks contains the following.

Headers, Cookies, Query String, POST Data 

In the Headers, It says that the request-type : SOAP Cookie, Query String has key value pairs and POST Data has a XML doc.

Can anyone help me to extend my existing code to send the request to fetch the report? I need answers to the following questions. Can we use the existing Curl handler $ch to send the second SOAP Request? If Yes, How can we specify it to use the cookie file I created? Also, How can I add the Query String and the XML POST data in the request? Any help would be much helpful.

Источник

SOAP request in PHP in CURL

It's have been already several days since I'm trying to figure out SOAP but no success 🙁 Any chance to know how can I create PHP(curl) SOAP request to look like this?

POST /WebServices/domain.asmx HTTP/1.1 Host: webservices.domain.ru Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://www.domain.ru/GetVariants"    string string string    xml    
WSDL: http://webservices.domain.ru/WebServices/domainXml.asmx?WSDL Soap action: http://webservices.domain.ru/WebServices/domainXml.asmx?op=GetVariants 

1 Answer 1

  1. PHP's support for SOAP just sucks.
  2. You need to use your WSDL to generate your PHP classes, so you can build a Request object.

You will get something like this:

class SomeClass < var $name; //NCName >class SomeOtherClass < var $value; //anonymous2 >. . . 

There are some WSDL to PHP scripts out there. (Google wsdl to php)

Then you do something like this.

$soapClient = new SoapClient($this->_wsdlUrl, array( 'trace' => true, 'exceptions' => true, 'uri' => $this->_endPoint, 'location' => $this->_endPoint, 'local_cert' => $this->certificatePath, 'allow_self_signed' => true, 'soap_version' => SOAP_1_2, )); // Build the SOAP client object, with your properties. //After that, you have to call: $yourContainerObject = new YourContainerObject(); // The top SOAP XML node $yourContainerObject->SomeChildNode = new SomeChildNode(); $yourContainerObject->SomeChildNode->Name = 'John'; . . . $soapResponse = $soapClient->GetVariants($yourContainerObject); print_r(soapResponse); // to see what you get 

The "GetVariants" method doesn't need to be implemented, so you don't get confused and ask yourself where do I get that from.It is described in WSLD and PHP's SOAP client knows that it is just a SOAP action.

This should be an more advanced example of creating SOAP requests via PHP. I hope you get the basic flow of this.

Источник

How to send XML soap request using php curl

I am sending request through soap using php curl getting java Exception. When I request for response I am getting error. I tried a lot at my end but problem is not solve.

$soap_request = ""; $soap_request .= "\n"; $soap_request .= " \n"; $soap_request .= " \n"; $soap_request .= " \n"; $soap_request .= " 1.0\n"; $soap_request .= " test@test.in\n"; $soap_request .= " 18641254455\n"; $soap_request .= " 1458445284\n"; $soap_request .= " 18-12-2015 13:45EST\n"; $soap_request .= " Android Browser\n"; $soap_request .= " Macintosh\n"; $soap_request .= " atinek@gmail.com\n"; $soap_request .= " mortgage-renewal\n"; $soap_request .= " success\n"; $soap_request .= " 
success
\n"; $soap_request .= " success\n"; $soap_request .= " success\n"; $soap_request .= " 325000\n"; $soap_request .= " 300000\n"; $soap_request .= " F3S2A2\n"; $soap_request .= " value\n"; $soap_request .= " yes\n"; $soap_request .= "
\n"; $soap_request .= "
\n"; $soap_request .= "
\n"; $soap_request .= "
"; $header = array( "Content-type: text/xml;charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "SOAPAction: myactionMethod", "Content-length: ".strlen($soap_request), ); $soap_do = curl_init(); curl_setopt($soap_do, CURLOPT_URL, $url ); curl_setopt($soap_do, CURLOPT_HEADER, false); curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 100); curl_setopt($soap_do, CURLOPT_TIMEOUT, 100); curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true ); curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($soap_do, CURLOPT_POST, true ); curl_setopt($soap_do, CURLOPT_POSTFIELDS, $soap_request); curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header); if(curl_exec($soap_do) === false) < $err = 'Curl error: ' . curl_error($soap_do); curl_close($soap_do); print $err; >else < $result = curl_exec($soap_do); echo '
'; print_r($result); curl_close($soap_do); //print 'Operation completed without any errors'; > 

soap:Serverjava.lang.ClassCastException: java.lang.String cannot be cast to javax.xml.bind.JAXBElement

Источник

Оцените статью