0

Is it possible to send headers and POST data with file_get_contents()?

I'm trying with the following code

$postdata = http_build_query(
    array(
        'var1' => 'some content',
        'var2' => 'doh'
    )
);
$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);
$context = stream_context_create($opts);
$result = file_get_contents('http://example.com/submit.php', false, $context);

but it's not working.

"file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in(...)"

you know what's wrong with the code?

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.