NYCPHP Meetup

NYPHP.org

[nycphp-talk] making a manual http POST using a PHP client (USPS web services)

drydell at att.net drydell at att.net
Mon Jul 12 12:21:04 EDT 2004


something like this:

$remote_url = 'http://SERVERNAME/ShippingAPI.dll';
$remote_server = 'http://SERVERNAME'
$request = 'API=Rate&XML='.$rateReqDoc->toString."\n\n";

$header = "POST $remote_url HTTP/1.0\n";
$header .= "Host: $remote_server\n";
$header .= "User-Agent: {$_SERVER['HTTP_USER_AGENT']}\n";
$header .= "Content-type: application/x-www-form-urlencoded\n";
$header .= "Content-length: ".strlen($request)."\n";
$header .= "Connection: Close\n\n";
$fp = fsockopen($remote_server, 80, &$errno, &$errstr);
if ($fp) {
 fputs($fp, "$header$request");
 $response = "<br><br>Connected to $remote_server$remote_url<br><br>RESPONSE :: <br>";
 while (!feof($fp)) {
  $response .= fgets($fp, 128);
 }
 fclose($fp);
 $return .= $response;
} else {
 $return = "<br><br>Cannot connect to $remote_server<br>errno::$errno<br>errstr::$errstr";
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20040712/3ae7eb38/attachment.html>


More information about the talk mailing list