Jump to content

Trying to Post to a HTTPS site


nathanblogs

Recommended Posts

Hey,

 

I'm Trying to post to a https without leaving my current site my code currently is

 

	
$postdata = http_build_query(
    array(
        'e' => $_POST['e'],
        'a' => $_POST['a'],
        'b' => $_POST['b'],
        'c' => $_POST['c'],
        'd' => $_POST['d'],
        'f' => 10
    )
); 

$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('https://example.com/', false, $context);

 

and I get the following error Warning: file_get_contents() [function.file-get-contents]: SSL: fatal protocol error in xx on line xx

 

Where the line it points to is

 $result = file_get_contents('https://example.com/', false, $context); 

Link to comment
https://forums.phpfreaks.com/topic/85110-trying-to-post-to-a-https-site/
Share on other sites

I found this,

 

$data = array ('foo' => 'bar', 'bar' => 'baz');
$data = http_build_query($data);

$context_options = array (
        'http' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
                . "Content-Length: " . strlen($data) . "\r\n",
            'content' => $data
            )
        );

$context = context_create_stream($context_options)
$fp = fopen('https://url', 'r', false, $context);

 

And I think it is working.

 

The site is suppose to send a Header back now I need to figure out how to catch that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.