• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP - How to send GET to a https using fsockopen() ?

stndn

Golden Member
Helo,

I'm trying to send a GET request to a script that resides at another server.
I could get it working if I were to send the GET request to a script residing in http:// on the server, by changing this line:

$fp= fsockopen ('ssl://' . $url['host'], $port, $errno, $errstr, 120);

to this line:

$fp= fsockopen ($url['host'], $port, $errno, $errstr, 120);


The problem comes when I want to send a GET request to the script that needs to be accessed through https:// request. The code below is supposedly what's used to send the request to https:// (from what I found on the net), but it always gives me an error page saying either: The parameter is incorrect or [p]Page not found[/p].

So, anyways, can someone give me a hint on how to send the GET request to a script through https?

Let's say I want to call https://www.mydomain.com/script.php?name=hello&text=world


Thanks.
 
I'm fresh out of ideas... I've never tried it before. I don't have a server that I can send GET requests to over SSL... if I did, I'd work on it a bit to see what I could find out.
 
Hmmm... after giving it a try again, it seems like my original code actually works.
The reason it didn't work the first time was that I specified wrong parameter to the GET request.

So, instead of:
GET {$url['path']}/?{$this->parameters} HTTP/1.1\n

It should've been without the extra '/' before the ?:
GET {$url['path']}?{$this->parameters} HTTP/1.1\n

Now a new problem is that the server replies with this:
Warning: fgets() [function.fgets]: SSL: fatal protocol error in /my/script/name.php on line 232

Whereas this warning message didn't occur if I use regular HTTP post

Any idea why it is?

Edit:
After further reading, it looks like the fault is at the server.
There's a bug with IIS which does not send the end of data marker:


Quote from PHP manual:
When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To workaround this, you should lower your error_reporting level not to include warnings. PHP 4.3.7 and higher can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning for you. If you are using fsockopen() to create an ssl:// socket, you are responsible for detecting and suppressing the warning yourself.

Okay, guess my script is not at fault anymore, then -)
 
Originally posted by: stndn
Hmmm... after giving it a try again, it seems like my original code actually works.
The reason it didn't work the first time was that I specified wrong parameter to the GET request.

So, instead of:
GET {$url['path']}/?{$this->parameters} HTTP/1.1\n

It should've been without the extra '/' before the ?:
GET {$url['path']}?{$this->parameters} HTTP/1.1\n

Now a new problem is that the server replies with this:
Warning: fgets() [function.fgets]: SSL: fatal protocol error in /my/script/name.php on line 232

Whereas this warning message didn't occur if I use regular HTTP post

Any idea why it is?

Edit:
After further reading, it looks like the fault is at the server.
There's a bug with IIS which does not send the end of data marker:


Quote from PHP manual:
When using SSL, Microsoft IIS will violate the protocol by closing the connection without sending a close_notify indicator. PHP will report this as "SSL: Fatal Protocol Error" when you reach the end of the data. To workaround this, you should lower your error_reporting level not to include warnings. PHP 4.3.7 and higher can detect buggy IIS server software when you open the stream using the https:// wrapper and will suppress the warning for you. If you are using fsockopen() to create an ssl:// socket, you are responsible for detecting and suppressing the warning yourself.

Okay, guess my script is not at fault anymore, then -)

i suspected something like this, though i didn't want to blab out my first thoughts and look like a retard. :|
 
Back
Top