How do I obtain the HTTP headers in response to a POST request I made with PHP?
+1
A:
you will find them in the superglobal $_SERVER
... anything that starts with HTTP_
should be a header ... it depends on the server, how well this will work ...
back2dos
2009-07-18 21:57:52
-1. He's asking about getting headers when his script is an HTTP client.
outis
2009-07-18 22:18:24
A:
How did you issue the POST? I use a socket and then read back the response where I get headers and body.
grantwparks
2009-07-18 22:01:34
i want to use a socket but I don't know how exactly to code it. From my C++ knowledge, I know I can do this job easily if I create a socket but how do I go about it in PHP?
Naumaan
2009-07-18 22:08:23
I plucked this out of an HTTP class I wrote, so all the niceties - error handling, etc - are missing, but I think it shows the basic steps.$fp = @fsockopen(HttpComm::$host, HttpComm::$port, $iErrno, $sErrStr, (int)self::$iTimeoutConnectionSecs);// send requestfputs($fp, $sHttpString, strlen($sHttpString));// this will get the string of headers$sResponse = stream_get_line($fp, 1024, "\r\n\r\n");// I break the HTTP response headers apart like soHttpComm::$headers = explode("\r\n", $sResponse);If you continue reading from this point you then it's the body of the response.
grantwparks
2009-07-18 23:18:45
A:
Create an HTTP stream context and pass it into file_get_contents()
. Afterwards, you can:
$metaData = stream_get_meta_data($context);
$headers = $metaData['wrapper_data'];
mrclay
2009-07-19 02:42:22