nathanblogs Posted January 9, 2008 Share Posted January 9, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/85110-trying-to-post-to-a-https-site/ Share on other sites More sharing options...
btherl Posted January 9, 2008 Share Posted January 9, 2008 I assume it's not example.com in your real code? Which version of php is this? There's a note here about problems caused by IIS running on the server. Quote Link to comment https://forums.phpfreaks.com/topic/85110-trying-to-post-to-a-https-site/#findComment-434154 Share on other sites More sharing options...
nathanblogs Posted January 9, 2008 Author Share Posted January 9, 2008 The version is 5.2.0-8 , it isn't run with IIS and yes the https address is different in the code . Quote Link to comment https://forums.phpfreaks.com/topic/85110-trying-to-post-to-a-https-site/#findComment-434168 Share on other sites More sharing options...
nathanblogs Posted January 9, 2008 Author Share Posted January 9, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85110-trying-to-post-to-a-https-site/#findComment-434176 Share on other sites More sharing options...
btherl Posted January 10, 2008 Share Posted January 10, 2008 The stream allows access to the body of the resource; the headers are stored in the $http_response_header variable. Since PHP 4.3.0, the headers are available using stream_get_meta_data(). This? Quote Link to comment https://forums.phpfreaks.com/topic/85110-trying-to-post-to-a-https-site/#findComment-435115 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.