Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP HTTP Request (stream_context_create)

Tags:

http

php

Hi I am trying to get the following to work. It is making the HTTP request because I can see it at the other end but it is not passing over the two values and parameters.

Can anyone help?

<?php

$url = "http://example.com/ws.php?uid=0000&pin=0000";
$fields = array(
    'target1' => $_GET['target1'],
    'target2' => $_GET['target2']);

$data = http_build_query($fields);

$context = stream_context_create(array(
'http' =>  array(
    'method'  => 'POST',
    'header'  => 'Content-type: application/x-www-form-urlencoded',
    'content' => $data,
)
));

$result = file_get_contents($url, false, $context);

echo $data."<br />";
echo($result); 

?>
like image 999
srob Avatar asked Jul 04 '26 11:07

srob


1 Answers

If PHP 5.2, see PHP bug https://bugs.php.net/bug.php?id=41051

Description:

the http wrapper ignores 'header' option in stream_create_context( ) if the value is not given as a simple array; neither a string nor a map (e.g. array('X-My-Header' => 'test')) will cause the additional headers to be sent.

like image 153
Ruslan Novikov Avatar answered Jul 07 '26 00:07

Ruslan Novikov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!