note 110449 modified in context.http by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Dec 2012 14:32:06 +0000 |
| Subject: | note 110449 modified in context.http by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192341@lists.php.net to get a copy of this message | ||
If you use the proxy server and encounter an error "fopen(http://example.com): failed to open
stream: HTTP request failed! HTTP/1.0 400 Bad Request" note that in many situations you need
also set the parameter "request_fulluri" to "true" in your stream options.
Without this option the php script sends the empty request to the server as "GET /
HTTP/0.0" and the proxy server replies to it with the "HTTP 400" error.
For example (working sample):
<?php
$stream = stream_context_create(Array("http" => Array("method" =>
"GET",
"timeout" => 20,
"header" => "User-agent:
Myagent",
"proxy" =>
"tcp://my-proxy.localnet:3128",
'request_fulluri' => True /*
without this option we get an HTTP error! */
)));
if ( $fp = fopen("http://example.com",
'r', false, $stream) ) {
print "well done";
}
?>
P>S> PHP 5.3.17
--was--
If you use the proxy server and encounter an error "fopen(http://someurl.com): failed to open
stream: HTTP request failed! HTTP/1.0 400 Bad Request" note that in many situations you need
also set the parameter "request_fulluri" to "true" in your stream options.
Without this option the php script sends the empty request to the server as "GET /
HTTP/0.0" and the proxy server replies to it with the "HTTP 400" error.
For example (working sample):
<?php
$stream = stream_context_create(Array("http" => Array("method" =>
"GET",
"timeout" => 20,
"header" => "User-agent:
Myagent",
"proxy" =>
"tcp://my-proxy.localnet:3128",
'request_fulluri' => True /*
without this option we get an HTTP error! */
)));
if ( $fp = fopen("http://someurl.com",
'r', false, $stream) ) {
print "well done";
}
?>
P>S> PHP 5.3.17
http://php.net/manual/en/context.http.php