POST SOAP Web-Services with PHP cURL (moving from SOAPUI) - php

I am totally stuck in SOAP integration. I have searched and continously searching for ways how to make it right. My system needs to connect to a certain web service. the URL redirects me to a ?wsdl page.
I am using SOAPUI to submit request, it is giving me the correct response. I also used SOAPClient but to no avail. I think this is no longer commonly used to this day. I can't find what my error is. Anyone can enlighten me with this? Thank you in advanced.
The SOAPUI request looks like this. It gives me the correct reponse:
POST https://example.com/blah/blah/Upload_v1_Port HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="upload_v1_Binder_ping"
Content-Length: 205
Host: bm-webservices-test.example.com.au
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Cookie: TS01128e1b=01c05e74c88cb127b6ba1e3cd907936f06957fdeead8e6f308ed6281d48b5da0dbb51b6ca0
Cookie2: $Version=1
Authorization: Basic <username:password>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:dir="http://test.com/mrb/ws/upload">
<soap:Header/>
<soap:Body>
<dir:ping/>
</soap:Body>
</soap:Envelope>
and this is my PHP Written code:
$credentials = "username:password";
$headers = array(
"POST https://example.com/blah/blah/Upload_v1_Port HTTP/1.1",
"Accept-Encoding: gzip,deflate",
"Content-Type: application/soap+xml;charset=UTF-8;action=upload_v1_Binder_ping",
"Content-Length: 205",
"Host: bfs-ws-test.test.com.au",
"Connection: Keep-Alive",
"User-Agent: Apache-HttpClient/4.1.1 (java 1.5)",
"Cookie: TS01128e1b=01c05e74c88cb127b6ba1e3cd907936f06957fdeead8e6f308ed6281d48b5da0dbb51b6ca0",
"Cookie2: $Version=1",
"Authorization: Basic $credentials",
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://www.test.com/upload');
curl_setopt($ch, CURLOPT_CERTINFO, CACERT);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_file);
$data = curl_exec($ch);
//pre_print_r($data); exit();
pre_print_r(curl_getinfo($ch));
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
} else {
echo 'test';
pre_print_r($data);
curl_close($ch);
}
And this is the result that I am getting:
</pre><hr>test<pre>--MIMEBoundary_ceea4229e38f12b7cd400440c7bdc1c1fe376164e3efa031
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <0.deea4229e38f12b7cd400440c7bdc1c1fe376164e3efa031#apache.org>
<faultstring>[ISS.0088.9171] Operation not found for soapAction = null</faultstring>

Solution :
it might caused by a wrong Content-Type in the HTTP POST. Setting text/xml in header may solve the problem.

Well you have 2 syntax errors:
$headers = array(
"POST https://example.com/blah/blah/Upload_v1_Port HTTP/1.1",
Accept-Encoding: gzip,deflate //no quotes no comma
"Content-Type: application/soap+xml;charset=UTF-8;action="upload_v1_Binder_ping", //3 qootes.
"Content-Length: 205",
"Host: bfs-ws-test.test.com.au",
"Connection: Keep-Alive",
"User-Agent: Apache-HttpClient/4.1.1 (java 1.5)",
"Cookie: TS01128e1b=01c05e74c88cb127b6ba1e3cd907936f06957fdeead8e6f308ed6281d48b5da0dbb51b6ca0",
"Cookie2: $Version=1",
"Authorization: Basic $credentials",
);
Or is it just a typo in the question.

Related

PHP curl is not parsing POST data

So i am trying to send a HTTPS POST request to a website but curl is not setting my post data nor my headers.
Here is my code(i changed the domain and values):
<?php
//Create connection
$ch = curl_init();
//Set the headers
$headers = array();
$headers[] = "Connection: Keep-Alive";
$headers[] = "Host: website.com";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
$headers[] = "Something: Something_Data";
//Set the POST data
$headers = array();
$headers[] = "Connection: Keep-Alive";
$headers[] = "Host: website.com";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
$headers[] = "Something: Something_Data";
// Configure the request (HTTPS)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "https://website.com/test");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "MyUserAgentHere");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, 1); //just to be sure...
//Set the POST data and Headers
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode("DATA1=VAL1&DATA2=VAL2"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result=curl_exec($ch);
echo $result;
curl_close($ch);
?>
So basically i'm trying to send a HTTPS POST request to https://website.com/test". The request is sent and i get an answer but for some reasons it doesn't parse the POST data nor the Headers.
Here is my request in fiddler:
POST https://website.com/test HTTP/1.1
Host: website.com
Here is the answer from the request:
HTTP/1.1 400 Bad Request
Date: Fri, 06 Nov 2015 00:57:15 GMT
Server: Apache
Cache-Control: no-store
Pragma: no-cache
Connection: close
Content-Type: application/json;charset=UTF-8
Content-Length: 158
{"error":"unsupported DATA1"}
As you can see, the POST data and the headers are not set in my request for some reason. I have no idea why curl is not setting my headers and my post fields.
Infos: I am using XAMPP with php5.
You shouldn't URL-encode the entire parameter string, that will encode the = and & so they're no longer delimiters. You should just encode the values.
curl_setopt($ch, CURLOPT_POSTFIELDS, 'DATA1=' . urlencode($val1) . '&DATA2' . urlencode($val2));
You can use an array instead, and cURL will do the encoding for you.
curl_setopt($ch, CURLOPT_POSTFIELDS, array('DATA1' => $val1, 'DATA2' => $val2));
If you use the array mechanism, remove the Content-type: application/x-www-form-urlencoded header, because cURL sends it in multipart/form-data format.

PHP - How to Automatically Post Form in Another Website and Parse the Result

I am new to screen-scaraping and curl. I am planning to create a website like what http://www.skyscanner.com.my/ is doing that will allow a user to pull the origin, destination and date from the http://airasia.com website. Then the website return the flight schedule and ticket price to the user. The following is my code so far:
code:
<?php
$post_data['Origin']=$_POST['origin'];
$post_data['Destination']=$_POST['destination'];
$post_data['From']=$_POST['departDate'];
$post_data['To']=$_POST['returnDate'];
foreach ($post_data as $key => $value)
{
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
$curl_connection = curl_init('https://booking.airasia.com/search.aspx');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, False);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
curl_error($curl_connection);
curl_close($curl_connection);
echo $result;
?>
The above do not return me any result from air asia. So i need some guidance to continue my task. Thank You
UPDATE
This Worked:
$request = array();
$request[] = "Host: mobile.airasia.com";
$request[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$request[] = "User-Agent: MOT-V9mm/00.62 UP.Browser/6.2.3.4.c.1.123 (GUI) MMP/2.0";
$request[] = "Accept-Language: en-US,en;q=0.5";
$request[] = "Connection: keep-alive";
$request[] = "Cache-Control: no-cache";
$request[] = "Pragma: no-cache";
$post = 'hash=61582ddd1b6ab8782ad63f1a6c6c1e46&trip-type=round-trip&origin=PEK&destination=SGN&date-depart-d=25&date-depart-my=2015-04&date-return-d=30&date-return-my=2015-04&passenger-count=1&child-count=0&infant-count=0&currency=MYR&depart-sellkey=&return-sellkey=&depart-details-index=&return-details-index=&depart-faretype=&return-faretype=&action=search&btnSearch=Search';
$url = 'https://mobile.airasia.com/en/search';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request);
curl_setopt($ch, CURLOPT_ENCODING,"");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_FAILONERROR,true);
curl_setopt($ch, CURLOPT_ENCODING,"");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$data = curl_exec($ch);
if (curl_errno($ch)){
$data .= 'Retreive Base Page Error: ' . curl_error($ch);
}
else {
$info = rawurldecode(var_export(curl_getinfo($ch),true));
// Get the cookies:
$skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE));
$requestHeader= substr($data,0,$skip);
$data = substr($data,$skip);
echo $data
Request Header.
POST /en/search HTTP/1.1
Accept-Encoding: deflate, gzip
Host: mobile.airasia.com
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: MOT-V9mm/00.62 UP.Browser/6.2.3.4.c.1.123 (GUI) MMP/2.0
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 366
Content-Type: application/x-www-form-urlencoded
Response Header:
HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Cache-control: no-cache="set-cookie"
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Mon, 20 Apr 2015 04:02:14 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Server: redishot
Set-Cookie: locale=en; expires=Mon, 20-Apr-2015 05:02:11 GMT; path=/; secure
Set-Cookie: currency=MYR; expires=Mon, 20-Apr-2015 05:02:11 GMT; path=/; secure
Set-Cookie: PHPSESSID=p8mjtiiga4615pnhuu6vl1htiqkqsn7v; path=/; HttpOnly
Set-Cookie: AWSELB=CDFDE3A70C862943856FF6079178A94249700C674BDFF1E117C02BF52443FE13448AB71BEA2EA3F41C01293A39C3579A0A03905034DA565F71B4820BD1807C5558B22ED5E0;PATH=/;MAX-AGE=1800
Vary: Accept-Encoding
transfer-encoding: chunked
Connection: keep-alive
This is the data you need from the returned HTML
Flight No.
Flight Time
Cost
.
Results","position":1}]}}' data-disabled><div class="smallFont farelist no-discount "><div class=flight-no>D7 317</div><div class=flight-time>02:15<br>12:10</div><div class=flight-info><div class=box><div class=total-price>MYR 2,091.42</div>
Results","position":2}]}}' data-disabled><div class="smallFont farelist no-discount "><div class=flight-no>D7 317</div><div class=flight-time>02:15<br>12:55</div><div class=flight-info><div class=box><div class=total-price>MYR 2,106.26</div>
Results","position":3}]}}' data-disabled><div class="smallFont farelist no-discount "><div class=flight-no>D7 317</div><div class=flight-time>02:15<br>15:50</div><div class=flight-info><div class=box><div class=total-price>MYR 2,483.82</div>
end of update
Do not prepend the "?" in the post data.
This is the format in the php manual:
$post = 'key1=value1&key2=value2&key3=value3';
You cannot curl http://booking.airasia.com/search.aspx because it requires javaScript.
You have to use the mobile site. When use a Browser to see the HTTP Request and Response Headers do it with JavaScript disabled on the Browser.
Use:
https://mobile.airasia.com/en/search
The problem is the mobile site is not functioning correctly right now and says to try later. so I could not get any further.
Regarding the post
This is what is being posted by the search:
Content-Type: application/x-www-form-urlencoded
Content-Length: 366
hash=26edce4024c5611451a2a95a74e2bf01
&trip-type=round-trip
&origin=KUL
&destination=OOL&date-depart-d=20
&date-depart-my=2015-04&date-return-d=25
&date-return-my=2015-04
&passenger-count=1
&child-count=0&infant-count=0
&currency=MYR
&depart-sellkey=
&return-sellkey=
&depart-details-index=
&return-details-index=
&depart-faretype=
&return-faretype=
&action=search
&btnSearch=Search
Because their form is application/x-www-form-urlencoded your are almost doing the $post_string correctly. You can use an array for the post data but if value is an array, the Content-Type header will be set to multipart/form-data, which should be OK.
Because it is application/x-www-form-urlencoded you must urlencode $post_string :
$post_string` = urlencode(implode ('&', $post_items));
To get the cookies, you do not need, and possibly never will need:
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, False);
Remove it.
You will be getting a redirect and may need the cookie jar:
curl_setopt($ch,CURLOPT_COOKIEFILE, "/tmp/cookie.txt")
You may need to set the request header to match the Browser Request:
Create an array to put the Request Header Key Values
Fill in the Request array with exactly what is in the Request header of your upload.
EXAMPLE:
$request = array();
$request[] = "Host: www.example.com";
$request[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
$request[] = "User-Agent: MOT-V9mm/00.62 UP.Browser/6.2.3.4.c.1.123 (GUI) MMP/2.0";
$request[] = "Accept-Language: en-US,en;q=0.5";
$request[] = "Connection: keep-alive";
$request[] = "Cache-Control: no-cache";
$request[] = "Pragma: no-cache";
Add to curl:
curl_setopt($ch, CURLOPT_HTTPHEADER, $request);
Checking the the headers in a Browser
Then I use FireFox Inspector or Chrome Development Tool.
I go to the Network Tab
In FireFox I go to Settings and turn on "Enable Persistent logs"
In Chrome I click "Preserve log" on the Network Tab
Then I use the Browser to go wherever I want curl to go.
Now I can see every Request and Response including redirects and compare them with the save headers.
Inspect: Step by Step
right click select Inspect Element
Select the Network tab
Refresh the page
Select Documents (chrome) or HTML (firefox)
Clear the list
Post your upload
Select the upload Request in the list of Requests
I use FireFox with user agent switcher using an old Motorola user agent to retrieve the headers and HTML. Then I use the same user agent in curl's HTTPHEADER:
request[] = 'User-Agent: MOT-V9mm/00.62 UP.Browser/6.2.3.4.c.1.123 (GUI) MMP/2.0
It is possible, not likely, the above cased the error when I tried
Your Query String $post_string is right but you are missing to prepend it with ? before sending curl. Try following:
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, "?".$post_string);

How do I set the headers to "application/x-www-form-urlencoded" on a XML based API Call

I am looking over the documentation for the VerMail API and they specify that I need to set the headers to "application/x-www-form-urlencoded" but I have to send the data as XML.. I know this is automatic if I send the data in an array but how would I do it with XML?
This is the code that I have so far:
$xmlcontent = "
<api>
<authentication>
<api_key>".$apiKey."</api_key>
<shared_secret>".$apiSecret."</shared_secret>
<response_type>xml</response_type>
</authentication>
<data>
<methodCall>
<methodname>legacy.message_stats</methodname>
<last>100</last>
</methodCall>
</data>
</api>
";
$xmlcontent = urlencode($xmlcontent);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "XML=".$xmlcontent);
$content = curl_exec($ch);
print_r($content);
This is what I see on the source code when I run it:
HTTP/1.1 200 OK
Date: Fri, 23 Jan 2015 20:17:52 GMT
Server: Apache
Cache-Control: max-age=18000
Expires: Sat, 24 Jan 2015 01:17:52 GMT
Content-Length: 595
Connection: close
Content-Type: text/xml;charset=utf-8
Set-Cookie: BIGipServerBH-gen-80=235023882.20480.0000; path=/
<?xml version="1.0" encoding="utf-8"?>
<methodResponse><item><error><![CDATA[1]]></error><responseText><![CDATA[ XML Error: Please verify the XML request is valid. For special characters please ensure you are using <![CDATA[ ]]]]><![CDATA[> blocks and url encoding data properly.]]></responseText><responseData><error><![CDATA[Not well-formed (invalid token) at line: 1]]></error><responseCode><![CDATA[425]]></responseCode></responseData><responseNum><![CDATA[1]]></responseNum><totalRequests><![CDATA[0]]></totalRequests><totalCompleted><![CDATA[0]]></totalCompleted></item></methodResponse>
Add the headers manually so you can specify that you are sending and want back XML
You should not have to URLencode the xml.
Also the postfields should be just the XML. not XML=$xmlcontent
$xmlcontent = "
<api>
<authentication>
<api_key>".$apiKey."</api_key>
<shared_secret>".$apiSecret."</shared_secret>
<response_type>xml</response_type>
</authentication>
<data>
<methodCall>
<methodname>legacy.message_stats</methodname>
<last>100</last>
</methodCall>
</data>
</api>
";
$xmlcontent = urlencode($xmlcontent);
$ch = curl_init();
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"Content-length: ".strlen($xmlcontent),
);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlcontent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$content = curl_exec($ch);

PHP CURL adds \0 (NUL Character) to method / Error 501 Method POST is not defined in RFC 2068

i have this curl script which is exported with Fiddler.
curl
-k
-i
--raw
-o 0.dat
-X POST
"https://192.168.178.103/ws/ResourceInteractionService"
-H "Content-Language: en-US"
-H "Content-Type: text/xml"
-H "SOAPAction: setResourceValues"
-H "Cache-Control: no-cache"
-H "Pragma: no-cache"
-H "User-Agent: Java/1.7.0_25"
-H "Host: 192.168.178.103"
-H "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
-H "Connection: keep-alive"
-H "Cookie: JSESSIONID=-1407060770673-59-927; s_pers=%%20s_fid%%3D3B17498CEA8BA6C4-2186ABA57F7ECAEB%%7C1466279984040%%3B%%20s_vs%%3D1%%7C1403123384042%%3B%%20s_nr%%3D1403121584045-Repeat%%7C1434657584045%%3B;JSESSIONID=-1407060770673-59-927"
That's my try.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://192.168.178.103/ws/ResourceInteractionService');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'SOAPAction: setResourceValues',
'Cookie: JSESSIONID=-1407060770673-59-927; s_pers=%%20s_fid%%3D3B17498CEA8BA6C4-2186ABA57F7ECAEB%%7C1466279984040%%3B%%20s_vs%%3D1%%7C1403123384042%%3B%%20s_nr%%3D1403121584045-Repeat%%7C1434657584045%%3B;JSESSIONID=-1407060770673-59-927',
'Content-Type: text/xml',
'Content-Language: en-US'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Java/1.7.0_25');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_POSTFIELDS, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:setResourceValues1 xmlns:ns1="utcs">
<ns1:arrayItem xsi:type="ns1:WSResourceValueEnvelope">
<ns1:value xmlns:ns2="utcs.values" xsi:type="ns2:WSBooleanValue">
<ns2:value xsi:type="xsd:boolean">true</ns2:value>
</ns1:value>
<ns1:typeString xsi:type="xsd:string"></ns1:typeString>
<ns1:resourceID xsi:type="xsd:int">25435</ns1:resourceID>
<ns1:isValueRuntime xsi:type="xsd:boolean">true</ns1:isValueRuntime>
</ns1:arrayItem>
</ns1:setResourceValues1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
list($header, $body) = explode("\r\n\r\n", curl_exec($ch), 2);
var_dump($header, $body);
curl_close($ch);
Thats the response $header.
HTTP/1.1 501 Method POST is not defined in RFC 2068 and is not supported by the Servlet API
content-type: text/html
date: Sun, 03-Aug-2014 11:32:26 GMT
keep-alive: timeout=900, max=1000
connection: Keep-Alive
content-length: 366
server: Rogatkin's JWS based on Acme.Serve/$Revision: 1.39 $
mime-version: 1.0
set-cookie: JSESSIONID=-1407060770673-59-927
And thats the response $body.
<HTML><HEAD><TITLE>501 Method POST is not defined in RFC 2068 and is not supported by the Servlet API </TITLE></HEAD><BODY BGCOLOR="#F1D0F2"><H2>501 Method POST is not defined in RFC 2068 and is not supported by the Servlet API </H2><HR><ADDRESS>Rogatkin's JWS based on Acme.Serve $Revision: 1.39 $</ADDRESS></BODY></HTML>
And thats the debug informations.
* About to connect() to 192.168.178.103 port 443 (#0)
* Trying 192.168.178.103...
* connected
* Connected to 192.168.178.103 (192.168.178.103) port 443 (#0)
* SSL connection using AES256-SHA
* Server certificate:
* subject: CN=IHC; O=Schneider Electric; C=FR
* start date: 2014-01-07 05:21:31 GMT
* expire date: 2034-01-02 05:21:31 GMT
* issuer: CN=IHC; O=Schneider Electric; C=FR
* SSL certificate verify result: self signed certificate (18), continuing anyway.
> POST /ws/ResourceInteractionService HTTP/1.1
User-Agent: Java/1.7.0_25
Host: 192.168.178.103
Accept: */*
SOAPAction: setResourceValues
Cookie: JSESSIONID=-1407060770673-59-927; s_pers=%%20s_fid%%3D3B17498CEA8BA6C4- 2186ABA57F7ECAEB%%7C1466279984040%%3B%%20s_vs%%3D1%%7C1403123384042%%3B%%20s_nr%%3D1403121584045-Repeat%%7C1434657584045%%3B;JSESSIONID=-1407060770673-59-927
Content-Type: text/xml
Content-Language: en-US
Content-Length: 746
* upload completely sent off: 746 out of 746 bytes
< HTTP/1.1 501 Method
Before the POST is a "NUL" symbol.
Maybe thats the problem?

curl with post method

salam
i want to get some xml responses from a server
but this server accept only xml request
i have this example of code
<?php
$url = "http://www.pj.ma/phonexmlfeeds";
$post_string = '<?xml version="1.0 encoding="UTF-8" ?><search_requests> <search_request id="req1"><content>statut=1 AND linguistic_expansion2(lingex_qui_quoi,1,0,"qui_quoi","Restaurant",LIN_EXACT|LIN_LEM0|LIN_LEM1|LIN_LEM2|LIN_SYN1|LIN_SYN2|LIN_PHO1|LIN_ORT)</content><code>sortBy(casanet_perfect(lingex_qui_quoi));filterBy(casanet_perfect_filter(lingex_qui_quoi));setSortAttribute(indice,sortDirection,sortDirectionDesc);sortBy(indice,score2(lingex_qui_quoi,lingex_ou,matrice), ordered(lingex_qui_quoi),ordered(lingex_ou),rs);catalogBy(libniv3);sendxref(rs);sendxref(crs);sendxref(nomcomm);sendxref(activite);sendxref(libniv3);sendxref(villep);sendxref(adrp);sendxref(nomvoie);sendxref(numtel_typetel);sendxref(internet);sendxref(pub);sendxref(marque);sendXrefHighlights();</code><options><option name="maxFiles">10</option><option name="startFiles">11</option><option name="highlight_zone_start">{match}</option><option name="highlight_zone_end">{/match}</option></options><metadata><meta name="base">Pages Jaunes</meta></metadata></search_request></search_requests>';
$header = "POST /phonexmlfeeds HTTP/1.1";
$header = "Connection: close";
$header .= "Content-Type: text/xml";
$header .= "User-Agent: Dalvik/1.4.0 (Linux; U; Android 2.3.3; GT-S5830 Build/GINGERBREAD)";
$header .= "Host: www.pj.ma";
$header .= "Content-Length: 1053";
$header .= "Accept-Encoding: gzip";
$header .= $post_string;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
$data = curl_exec($ch);
if(curl_errno($ch))
print curl_error($ch);
else
curl_close($ch);
echo $data;
?>
but it give this response
Your browser sent a request that this server could not understand.
here i post a example of request captured by wifisnifer
POST /phonexmlfeeds HTTP/1.1 Connection: close Content-Type: text/xml
User-Agent: Dalvik/1.4.0 (Linux; U; Android 2.3.3; GT-S5830
Build/GINGERBREAD) Host: www.pj.ma Content-Length: 1052
Accept-Encoding: gzip
<?xml version="1.0 encoding="UTF-8" ?><search_requests> <search_request id="req1"><content>statut=1 AND linguistic_expansion2(lingex_qui_quoi,1,0,"qui_quoi","Restaurant",LIN_EXACT|LIN_LEM0|LIN_LEM1|LIN_LEM2|LIN_SYN1|LIN_SYN2|LIN_PHO1|LIN_ORT)</content><code>sortBy(casanet_perfect(lingex_qui_quoi));filterBy(casanet_perfect_filter(lingex_qui_quoi));setSortAttribute(indice,sortDirection,sortDirectionDesc);sortBy(indice,score2(lingex_qui_quoi,lingex_ou,matrice), ordered(lingex_qui_quoi),ordered(lingex_ou),rs);catalogBy(libniv3);sendxref(rs);sendxref(crs);sendxref(nomcomm);sendxref(activite);sendxref(libniv3);sendxref(villep);sendxref(adrp);sendxref(nomvoie);sendxref(numtel_typetel);sendxref(internet);sendxref(pub);sendxref(marque);sendXrefHighlights();</code><options><option name="maxFiles">10</option><option name="startFiles">1</option><option name="highlight_zone_start">{match}</option><option name="highlight_zone_end">{/match}</option></options><metadata><meta name="base">Pages Jaunes</meta></metadata></search_request></search_requests>
For custom headers add line breaks (\r\n).
Or consider using http://us3.php.net/curl_setopt for headers, eg:
curl_setopt($ch, CURLOPT_HTTPHEADERS, array(
'POST /phonexmlfeeds HTTP/1.1',
'Connection: close',
'Content-Type: text/xml',
etc...
));
Edit this line --
$header .= "Connection: close";
as you have--
$header = "Connection: close";

Categories