Hi,
I have a problem. I'm posting some XML data to my client's website using HTTP Post. Assume I'm posting to getxml.php (hosted on my clients server). Now my client has put authentication on his website using
header('WWW-Authenticate: Basic realm="Private Area"');
Now the page getxml.php asks me to prove my identity before it acceps my xml posts.
So how do I send the username & pwd when I'm posting the xml details?
My client doesn't want to forego this authentication concept.
To post, this is what I'm doing
function dopost( $host, $usepath, $postdata = "", $logfilename ) {
//Global $logfilename;
//
// open socket to files that accept posts on other servers
//
$fp = fsockopen( $host, 80, &$errno, &$errstr, 60 );
//
// check that the socket has been opened successfully
//
if( !$fp ) {
//print "---------$errstr ($errno)---------<br>\n";
$this->postURL = "http://".$host.$usepath."?".$postdata;
$this->writeToErrorLog($logfilename);
}
else {
#write the data to the encryption cgi
fputs( $fp, "POST $usepath HTTP/1.0\n");
$strlength = strlen( $postdata );
fputs( $fp, "Content-type: application/x-www-form-urlencoded\n" );
fputs( $fp, "Content-length: ".$strlength."\n\n" );
fputs( $fp, $postdata."\n\n" );
//
// clear the response data
//
$output = "";
//
// read the response from the remote cgi
//
// while content exists, keep retrieving document in 1K chunks
//
while( !feof( $fp ) ) {
$output .= fgets( $fp, 1024);
}
//
// close the socket connection
//
fclose( $fp);
}
//
// return the response
//
return $output;
}
Also I have tried the following, still it doesn't work
fputs( $fp, "POST $usepath HTTP/1.0\n");
$strlength = strlen( $postdata );
//fputs( $fp, "Authorization: " . base64_encode ( $username . ":" . $password) . "\n");
//fputs( $fp, "Authorization: " . base64_encode ("guest:guest")."\n");
fputs( $fp, "Authorization: " . "guest:guest"."\n");
fputs( $fp, "Content-type: application/x-www-form-urlencoded\n" );
fputs( $fp, "Content-length: ".$strlength."\n\n" );
fputs( $fp, $postdata."\n\n" );
Still nothing works out..
Plz help me. I need this badly now.
Bobbie