Need response with fputs and fget.
Posted: Wed Oct 09, 2002 4:04 am
Hi everyone,
I am troubled! What the below snippet is meant to do is send a bunch of data using the socket connection then receive a response to that data and print it out. It does not give an error; instead it just loads and loads until I believe it times out then just loads a blank html file. Also the site it is connecting too is a remote secure server, prepared to handle scripts sending the appropriate data.
Snippet:
$data = "variable=1";
$host = "www.mysite.com";
$method = "POST";
$path = "/cgi-bin/gatway.cgi";
$fp = fsockopen($host,80);
fputs($fp, "$method $path\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: " . strlen($data) . "\n");
$result = fgets($fp);
fclose($fp);
list(variable1,$variable2) = split ("|", $result);
echo "$variable1,$variable2";
To try and explain what I mean, this is a Windows NT/2000 Perl 5.6 – IE 5.01 Object Method example snippet that does work:
use WIN32::OLE;
$SendObject=Win32::OLE->new('microsoft.XMLhttp');
$SendObject->open("POST", "https://www.mysite.com/cgi-bin/gateway.cgi", "false");
$SendObject->setRequestHeader("Content-type", "text/plain");
$SendObject->send ($Postvals);
$Result = $SendObject->responseText;
($variable1,$variable2) = split(/\|/, $Result);
Here is a Unix/Windows NT/2000 Perl 5.6 – Crypt Module Installed example snippet that works:
use LWP::UserAgent;
use Crypt::SSLeay;
$ua = new LWP::UserAgent;
$ua->agent("SSL/0.1");
my $req = new HTTP::Request('POST', 'https://www.mysite.com/cgi-bin/gateway.cgi');
$req->content_type('application/x-www-form-urlencoded');
$req->content($Postvals);
my $res = $ua->request($req);
$Result = $res->content;
($variable1,$variable2) = split(/\|/, $Result);
Here is a Windows NT/2000 VBScript ASP Object Method example snippet:
Set SendObject = Server.CreateObject("Microsoft.XMLhttp")
SendObject.open "POST","https://www.mysite.com/cgi-bin/gateway.cgi",false
SendObject.setRequestHeader "Content-type", "text/plain"
SendObject.send Postvals
Result = SendObject.responseText
SplitArray = split(Result, "|", -1, 1)
success = SplitArray(0)
authcode = SplitArray(1)
authresponse = SplitArray(2)
avscode = SplitArray(3)
oid = SplitArray(4)
All of the examples work fine but I cannot use them because I am running a Linux server with Apache and PHP installed without the capabilities.
I figured there must be something that I am missing and I would be very grateful for any help!
I am troubled! What the below snippet is meant to do is send a bunch of data using the socket connection then receive a response to that data and print it out. It does not give an error; instead it just loads and loads until I believe it times out then just loads a blank html file. Also the site it is connecting too is a remote secure server, prepared to handle scripts sending the appropriate data.
Snippet:
$data = "variable=1";
$host = "www.mysite.com";
$method = "POST";
$path = "/cgi-bin/gatway.cgi";
$fp = fsockopen($host,80);
fputs($fp, "$method $path\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: " . strlen($data) . "\n");
$result = fgets($fp);
fclose($fp);
list(variable1,$variable2) = split ("|", $result);
echo "$variable1,$variable2";
To try and explain what I mean, this is a Windows NT/2000 Perl 5.6 – IE 5.01 Object Method example snippet that does work:
use WIN32::OLE;
$SendObject=Win32::OLE->new('microsoft.XMLhttp');
$SendObject->open("POST", "https://www.mysite.com/cgi-bin/gateway.cgi", "false");
$SendObject->setRequestHeader("Content-type", "text/plain");
$SendObject->send ($Postvals);
$Result = $SendObject->responseText;
($variable1,$variable2) = split(/\|/, $Result);
Here is a Unix/Windows NT/2000 Perl 5.6 – Crypt Module Installed example snippet that works:
use LWP::UserAgent;
use Crypt::SSLeay;
$ua = new LWP::UserAgent;
$ua->agent("SSL/0.1");
my $req = new HTTP::Request('POST', 'https://www.mysite.com/cgi-bin/gateway.cgi');
$req->content_type('application/x-www-form-urlencoded');
$req->content($Postvals);
my $res = $ua->request($req);
$Result = $res->content;
($variable1,$variable2) = split(/\|/, $Result);
Here is a Windows NT/2000 VBScript ASP Object Method example snippet:
Set SendObject = Server.CreateObject("Microsoft.XMLhttp")
SendObject.open "POST","https://www.mysite.com/cgi-bin/gateway.cgi",false
SendObject.setRequestHeader "Content-type", "text/plain"
SendObject.send Postvals
Result = SendObject.responseText
SplitArray = split(Result, "|", -1, 1)
success = SplitArray(0)
authcode = SplitArray(1)
authresponse = SplitArray(2)
avscode = SplitArray(3)
oid = SplitArray(4)
All of the examples work fine but I cannot use them because I am running a Linux server with Apache and PHP installed without the capabilities.
I figured there must be something that I am missing and I would be very grateful for any help!