Send HTTP Header Problem
Posted: Fri Oct 07, 2005 4:02 pm
I'm currently writing a script that will send XML formatted text to an ASP script located on a remote server. I'm having problems with it, and its returning this: "Bad Request (Invalid Hostname)" I know that the url and path are correct because I can send it a string directly through the browser and I get something back. Any help would be greatly appreciated.
Thanks in advance.
Code: Select all
$server = "api-test.corporate.marketworks.com";
$port = 80;
$path = "/api/apiCall.asp";
$s_out = "test";
http_post_url($server, $port, $path, $s_out);
function http_post_url($server, $port, $path, $post_data) {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$content_length = strlen($post_data);
$fp = fsockopen($server, $port, $errno, $errstr);
if (!$fp) {
return false;
}
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "User-Agent: $user_agent");
fputs($fp, "Host: $server\r\n");
fputs($fp, "Content-Type: text/xml\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, "\r\n");
fputs($fp, $post_data);
$ret = "";
while (!feof($fp))
$ret.= fgets($fp, 1024);
fclose($fp);
echo $errstr;
echo $ret . "\n\n";
}