Getting content body from http post using php CURL
I am trying to debug an http post the I am trying to send from list application. I have been able to send the correct post from php CURL which corectly interfaces with my drupal 7 website and uploads an image.
In order to get this to work in my lisp application I really need to see the content body of my http post I have been able to see the headers using a call like this:
curl_setopt($curl, CURLOPT_STDERR, $fp); curl_setopt($curl, CURLOPT_VERBOSE, 1);
and the headers look the same in my lisp application but I have been unable to examine the body of the post. I have searched online and other people have asked this question but no one posted a response.
The content type of my http post is:
I have also tried many http proxy debuging tools but they only ever the http GET to get my php page but never capture the get sent from server once the php code is executed.
EDIT: I have added a code snipet showing where I actually upload the image file.
// file $file = array( 'filesize' => filesize($filename), 'filename' => basename($filename), 'file' => base64_encode(file_get_contents($filename)), 'uid' => $logged_user->user->uid, ); $file = http_build_query($file); // REST Server URL for file upload $request_url = $services_url . '/file'; // cURL $curl = curl_init($request_url); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded')); curl_setopt($curl, CURLOPT_STDERR, $fp); curl_setopt($curl, CURLOPT_VERBOSE, 1); curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST curl_setopt($curl, CURLOPT_POSTFIELDS, $file); // Set POST data curl_setopt($curl, CURLOPT_HEADER, FALSE); // Ask to not return Header curl_setopt($curl, CURLOPT_COOKIE, "$cookie_session"); // use the previously saved session curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_FAILONERROR, TRUE); curl_setopt_array($curl, array(CURLINFO_HEADER_OUT => true) ); $response = curl_exec($curl);
If you need to inspect the request body,
CURLOPT_VERBOSE should give that to you but I'm not totally sure.
In any case, a good network sniffer should give you all the details transparently.
$curlOptions = array( CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_VERBOSE => TRUE, CURLOPT_STDERR => $verbose = fopen('php://temp', 'rw+'), CURLOPT_FILETIME => TRUE, ); $url = "http://stackoverflow.com/questions/tagged/java"; $handle = curl_init($url); curl_setopt_array($handle, $curlOptions); $content = curl_exec($handle); echo "Verbose information:\n", !rewind($verbose), stream_get_contents($verbose), "\n"; curl_close($handle); echo $content;
Verbose information: * About to connect() to stackoverflow.com port 80 (#0) * Trying 184.108.40.206... * connected * Connected to stackoverflow.com (220.127.116.11) port 80 (#0) > GET /questions/tagged/java HTTP/1.1 Host: stackoverflow.com Accept: */* < HTTP/1.1 200 OK < Cache-Control: private < Content-Type: text/html; charset=utf-8 < Date: Wed, 14 Mar 2012 19:27:53 GMT < Content-Length: 59110 < * Connection #0 to host stackoverflow.com left intact <!DOCTYPE html> <html> <head> <title>Newest 'java' Questions - Stack Overflow</title> <link rel="shortcut icon" href="http://cdn.sstatic.net/stackoverflow/img/favicon.ico"> <link rel="apple-touch-icon" href="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png"> <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml"> ...
Execute a HTTP POST Using PHP CURL, Learn how to execute a remote HTTP POST using PHP's CURL library. //extract data from the post //set POST variables $url = 'http://domain.com/get-post.php'; $fields = array( please any body knows about this please let me know i want to send the the content of dynamic webpage to email using php I am trying to debug an http post the I am trying to send from list application. I have been able to send the correct post from php CURL which corectly interfaces with my drupal 7 website and uplo
Just send it to a random local port and listen on it.
# terminal 1 nc -l localhost 12345 # terminal 2 php -e <?php $curl = curl_init('http://localhost:12345'); // etc
POSTing JSON Data With PHP cURL, http://mark.koli.ch/remember-kids-an-http-content-length-is-the-number-of-bytes-not- Sample JSON POST body to [single endpoint] /mmmr Pingback: How to use PHP curl GET and POST with JSON web services | p6abhu. The PHP cURL is a library used for making HTTP requests. In order to use PHP cURL, you must have installed and enabled libcurl module for PHP on your system. In this tutorial, you will learn how to POST JSON data with PHP cURL requests. Basically, there are 4 steps involved to complete a cURL request using PHP.
How To POST JSON Data with PHP cURL, The PHP cURL is a library used for making HTTP requests. In 'Content-Type: application/json', must be a POST request with properly json-encoded data in the body. How to make a get request to the api using cURL. The name of a callback function where the callback function takes two parameters. The first is the cURL resource, and the second is a string with the data to be read. Using this callback function, it becomes your responsibility to read the data. Return the number of bytes read. Return 0 to signal EOF.
If you're talking about viewing the response, if you add
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );, then the document returned by the request should be returned from your call to
If you're talking about viewing the postdata you are sending, well, you should be able to view that anyway since you're setting that in your PHP.
EDIT: Posting a file, eh? What is the content of
$file? I'm guessing probably a call to
Try something like this:
$postdata = array( 'upload' => '@/path/to/upload/file.ext' ); curl_setopt( $curl, CURLOPT_POSTFIELDS, $postdata );
You can't just send the file, you still need a postdata array that assigns a key to that file (so you can access in PHP as
$_FILES['upload']). Also, the
@ tells cURL to load the contents of the specified file and send that instead of the string.
curl_setopt - Manual, CURLOPT_NOBODY, TRUE to exclude the body from the output. Proxy headers must be set with CURLOPT_PROXYHEADER to get used. CURLOPT_COOKIE, The contents of the "Cookie: " header to be used in the HTTP request. User will submit the form, as usual. In the form processing PHP, I use cURL to execute a POST transmission to a PHP script on the customer's server. The remote script would do a MySQL INSERT query into the customer's private database.
I think you're better off doing this with a proxy than in the PHP. I don't think it's possible to pull the raw POST data from the PHP CURL library.
A proxy should show you the request and response contents
PHP cURL POST Request - PHP, I want to sent XML content(string) in the request body of the POST request. This string No, this is for GET request. <?php $durl = "http://yourURLhere"; $curl = curl_init(); curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: ". Initiate new cURL resource using curl_init(). Setup data in PHP array and encode into a JSON string using json_encode(). Attach JSON data to the POST fields using the CURLOPT_POSTFIELDS option. Set the Content-Type of request to application/json using the CURLOPT_HTTPHEADER option.
PHP Curl Examples - PHP cURL Post, Get, Header, PHP has the option to use cURL and in this article, we'll show several examples. curl_init('http://hostname.tld/api'); curl_setopt($cURLConnection, When talking to a HTTP 1.1 server, you can tell curl to send the request body without a Content-Length: header upfront that specifies exactly how big the POST is. By insisting on curl using chunked Transfer-Encoding, curl will send the POST "chunked" piece by piece in a special style that also sends the size for each such chunk as it goes along.
Sending POST form data with php CURL, Sending POST form data with php CURL. or to use GET instead of POST To make a simple HTTP POST with text/xml as content-type, do something like: CURLOPT_NOBODY: TRUE to exclude the body from the output. Basic curl example. Once you've compiled PHP with cURL support, you can begin using the cURL functions. The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close().
How to use PHP curl and curl_setopt with JSON web services , Here are two PHP scripts I just wrote that use curl and curl_setopt . This first example makes an HTTP GET request and prints the data that is returned by CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', -w, --write-out <format> Make curl display information on stdout after a completed transfer. See man page for more details on available variables. Convenient way to force curl to append a newline to output: -w " " (can add to ~/.curlrc ). -X, --request The request method to use. When sending data via a POST or PUT request, two common formats