PHP POST with custom headers giving HTTP 400 Bad Request Response (Bug?) -
i'm having trouble posting data client machine our internal site using php. server accepts data via https basic authentication. here code i'm using post with:
$parameters = array('http' => array( 'method' => 'post', 'content' => $data ) ); if ($optionalheaders !== null) { $parameters['http']['header'] = $optionalheaders; } $ctx = stream_context_create($parameters); $fp = fopen($url, 'rb', false, $ctx);
with following header:
$postheader = "post /index.php http/1.1\r\n". "host:my.host\r\n". "content-type: application/x-www-form-urlencoded\r\n". "user-agent: php-code\r\n". "content-length: " . strlen($postdata) . "\r\n". "authorization: basic ".base64_encode($user.':'.$password)."\r\n". "connection: close\r\n";
now, can work, , posts fine on 1 of clients php version 5.2.5, on client error message:
fopen(magical_url): failed open stream: http request failed! http/1.1 400 bad request
and apache error log gives:
request failed: error reading headers
the difference can see latter client has php version 5.1.6. know if bug? or doing wrong somewhere... i've looked through php site , found bug listed version 5.2.6 of php https://bugs.php.net/bug.php?id=45540 post-dates version works on!
thanks, jak
you should not provide headers. that's bound fail.
headers post, host, content-length , connection automatically provided. remove optional headers (should work then) , add them step step.
Comments
Post a Comment