Forum Moderators: coopster
$fp = @fsockopen("www.site.com", 80, $errno, $errstr, 5);
$header = "POST test_post.php HTTP/1.0\r\n";
$header .= "Host: www.site.com \r\n";
$header .= "Accept: */*\r\n";
$header .= "Content-Length: ". strlen($querystring) ."\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Connection: Close\r\n";
$header .= $querystring;
fwrite($fp, $header);
$data = "";
while(!feof($fp)){
$data .= @fgets($fp, 1024);
}
fclose($fp);
Page: test_post.php on www.site2.com:
$fp = @fsockopen("www.site.com", 80, $errno, $errstr, 5);
$querystring = "asdf=". urlencode("test var");
$header = "POST verify_post.php HTTP/1.0\r\n";
$header .= "Host: www.site.com \r\n";
$header .= "Accept: */*\r\n";
$header .= "Content-Length: ". strlen($querystring) ."\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Connection: Close\r\n";
$header .= $querystring;
fwrite($fp, $header);
$data = "";
while(!feof($fp)){
$data .= @fgets($fp, 1024);
}
fclose($fp);
Page: verify_post.php on www.site.com:
$fp = @fsockopen("www.site2.com", 80, $errno, $errstr, 5);
if($_POST['asdf']){
$querystring = "asdf=". urlencode("it works");
}
$header = "POST test_post.php HTTP/1.0\r\n";
$header .= "Host: www.site2.com \r\n";
$header .= "Accept: */*\r\n";
$header .= "Content-Length: ". strlen($querystring) ."\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Connection: Close\r\n";
$header .= $querystring;
fwrite($fp, $header);
fclose($fp);
if(!isset($_POST)){
$fp = @fsockopen("www.site.com", 80, $errno, $errstr, 5);
$querystring = "asdf=". urlencode("test var");$header = "POST verify_post.php HTTP/1.0\r\n";
$header .= "Host: www.site.com \r\n";
$header .= "Accept: */*\r\n";
$header .= "Content-Length: ". strlen($querystring) ."\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Connection: Close\r\n";
$header .= $querystring;fwrite($fp, $header);
fclose($fp);
}else{
$querystring = "asdf=". urlencode("it works");
}
Page: verify_post.php on www.site.com:
$fp = @fsockopen("www.site2.com", 80, $errno, $errstr, 5);if($_POST['asdf']){
$querystring = "asdf=". urlencode("it works");
}$header = "POST test_post.php HTTP/1.0\r\n";
$header .= "Host: www.site2.com \r\n";
$header .= "Accept: */*\r\n";
$header .= "Content-Length: ". strlen($querystring) ."\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Connection: Close\r\n";
$header .= $querystring;fwrite($fp, $header);
fclose($fp);
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach($_POST as $key => $value){
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
if(!$fp){
// HTTP ERROR
}else{
fputs($fp, $header . $req);
while(!feof($fp)){
$res = fgets ($fp, 1024);
}
}
fclose ($fp);
This is the post string:
POST /cgi-bin/search.pl?hal&fo=s HTTP/1.1 Host: www.blahblah.org.uk User-Agent: PostIt Content-Type: application/x-www-form-urlencoded Content-Length: 92
sales_rental=S&type=&num_beds=&price_low=&price_high=&keywords=&search_request_button=Search
And this the response i always get:
HTTP/1.1 400 Bad Request Content-Type: text/html Date: Fri, 10 Jun 2005 16:18:25 GMT Connection: close
Content-Length: 20
Bad Request
Have no idea why the receiving script thinks content-type is text/html and length 20. HTTP/1.0 also gives same results. Yet I can create a form to post to the same script fine?