In any case, a good network sniffer should give you all the details transparently. 1 Answer Sorted by: 1 I think you need to pass curl to the curlgetinfo method, not the response response curlexec (curl) theInfo curlgetinfo (curl) httpcode theInfo 'httpcode' You can see the doco here. If you need to inspect the request body, CURLOPT_VERBOSE should give that to you but I'm not totally sure. However, we can still cut them from the full response. If you're looking for the response body content, you can also use CURLOPT_RETURNTRANSFER, curl_exec() will then return the response body. There is no build-in way to only return the response headers using cURL in PHP. 'file' => base64_encode(file_get_contents($filename)),Ĭurl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded')) Ĭurl_setopt($curl, CURLOPT_POST, 1) // Do a regular HTTP POSTĬurl_setopt($curl, CURLOPT_POSTFIELDS, $file) // Set POST dataĬurl_setopt($curl, CURLOPT_HEADER, FALSE) // Ask to not return HeaderĬurl_setopt($curl, CURLOPT_COOKIE, "$cookie_session") // use the previously saved sessionĬurl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE) Ĭurl_setopt($curl, CURLOPT_FAILONERROR, TRUE) Ĭurl_setopt_array($curl, array(CURLINFO_HEADER_OUT => true) ) ĬURLOPT_VERBOSE should actually show the details. 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.ĮDIT: I have added a code snipet showing where I actually upload the image file. The content type of my http post is: application/x-www-form-urlencoded I have searched online and other people have asked this question but no one posted a response. 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) Īnd the headers look the same in my lisp application but I have been unable to examine the body of the post. I have been able to send the correct post from php CURL which corectly interfaces with my drupal 7 website and uploads an image. Here is a tested working code: function HandleHeaderLine( $curl, $header_line ) elseif (substr($header, 0, 8) = 'HTTP/1.I am trying to debug an http post the I am trying to send from list application. Your callback function then can do anything with it (and must return the number of bytes of the given line). Curl will pass the header (and the header only!) to this callback function, line-by-line (so the function will be called for each header line, starting from the top of the header section). The value of this option must be the name of a callback function. $headers))] = trim($header) Ĭurl has a built in option for this, called CURLOPT_HEADERFUNCTION. I would like to forward the full HTTP request made to server 1, to server 2, so that when a user sends an HTTP request to main.php (server 1), it would get the response from main.php on server 2. I have a PHP page main.php (same page, different code) on server 2. If (count($header) < 2) // ignore invalid headers I have a PHP page, main.php which is on server 1. this function is called by curl for each header received This complies with RFC822 and RFC2616, please do not make use of the mb_ (and similar) string functions, it is a not only incorrect but even a security issue RFC-7230! $ch = curl_init() Ĭurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) This version will retain duplicated headers It also converts all headers to lowercase for consistent handling across servers and HTTP versions. Here is a very clean method of performing this using PHP closures. The most correct method is using CURLOPT_HEADERFUNCTION. I hatched the idea to use curl to connect from the external server to the internal server (using request variables to send queries) and return everything (data and headers) returned by the file server. Detecting the size of the headers via CURLINFO_HEADER_SIZE is also not always reliable, especially when proxies are used Curl-1204 or in some of the same redirection scenarios. For example, we could modify the Referer, Cookie, User-Agent or Accept-Encoding headers.Not all servers are standards compliant and transmit just a \n for new lines (and a recipient may discard the \r in the line terminator) Q&A.Splitting on \r\n\r\n is not reliable when CURLOPT_FOLLOWLOCATION is on or when the server responds with a 100 code RFC-7231, MDN.Along with their purpose, required for this example are described below: curlinit (): Used to initialize a curl object. The function will receive the curl object and a string with the header line. Many of the other solutions offered this thread are not doing this correctly. The functions provide an option to set a callback that will be called for each response header line.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |