List Info

Thread: POST with file_get_contents is possible




POST with file_get_contents is possible
country flaguser name
United States
2007-09-15 00:32:27

I just thought this was kinda strange... the very first article on the
front page of the PHP Developer Center compares using curl vs
file_get_contents for REST requests. It states that file_get_contents
is simple but doesn't work for POSTs, which is incorrect for PHP > 5.
You can use the context parameter to do a POST using file_get_contents.

$context_options['http']['method'] = 'POST';
$context_options['http']['header'] = $header; // "POST $uri
HTTP/1.0rnContent-Length: $content_lengthrnrn"
$context_options['http']['content'] = $post_content;

$context = stream_context_create($context_options);
$response = file_get_contents($filename, false, $context);

source article: http://developer.yahoo.com/php/howto-reqRestPhp.html

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )