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

stndn

Golden Member
Mar 10, 2001
1,886
0
0
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.
 
 

GeekDrew

Diamond Member
Jun 7, 2000
9,099
19
81
Are you using PHP 4.3.0 or above, and is OpenSSL support compiled in?
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
We are using PHP 5 in our server.
And yah got OpenSSL : OpenSSL 0.9.7a Feb 19 2003
 

GeekDrew

Diamond Member
Jun 7, 2000
9,099
19
81
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.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
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 -)
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
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. :|