Getting Curl request body content

82 views
Skip to first unread message

vishal

unread,
Feb 23, 2014, 9:23:21 AM2/23/14
to professi...@googlegroups.com
Hi All,

Seems group is inactive for longtime. Is this something to do with people not interested in php anymore or what? It seems market demand for PHP are also shrinking these days. Anyway lets hope for better.

My question is related to Curl.

I am trying to capture body content of curl request.but it is not working.Following is my code


$post = json_encode(array('vishal'=>1,'vishal2'=>3));

$ch = curl_init($url);
$f = fopen('request.txt', 'a+');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLINFO_HEADER_OUT,true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post); //dumping all data to post content
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_STDERR,$f);  //log header trace in one file
echo $result = curl_exec($ch);
$header_info = curl_getinfo($ch,CURLINFO_HEADER_OUT);


In file, i am able to get details related to header not body content.example below

* About to connect() to localhost port 80 (#0)
*   Trying 127.0.0.1... * connected
> POST /test/wsdl/hello_server.php HTTP/1.1
Host: localhost
Accept: */*
Content-Length: 24
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 24out of 24 bytes
< HTTP/1.1 500 Internal Service Error
< Date: Sun, 23 Feb 2014 07:22:30 GMT
< Server: Apache/2.4.6 (Ubuntu)
< X-Powered-By: PHP/5.5.7-1+sury.org~precise+1
< Content-Length: 278
< Connection: close
< Content-Type: text/xml; charset=utf-8
< 
* Closing connection #0

It's sound funny as i am asking for content which my code is preparing but i need content to make debug log. As in Soap client we generally get content details using

$response = $sClient->doHello($params);
echo "REQUEST HEADERS:\n" . $Client->__getLastRequest() . "\n"; 
 
Thought there should be same way to get in curl too. Any idea?

Regards,
Vishal

Robert Gonzalez

unread,
Feb 23, 2014, 7:55:21 PM2/23/14
to professional-php
Why are you not just inspecting $_POST on the server side of this exchange? If for some reason the $_POST array isn't being sent by your post request, you might be able to get away with reading from php://input (using file_get_contents() and the like). From there however you might have to use parse_str() on the content, as the data would have more than likely have been sent in a querystring format in the body.


--
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to professional-p...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

Robert Gonzalez
   

Ovidiu Alexa

unread,
Apr 4, 2014, 6:18:38 AM4/4/14
to professi...@googlegroups.com
node.js
Reply all
Reply to author
Forward
0 new messages