
David Covert - 2009-03-02 17:18:49
I think I must be very close to getting this to work, but so far, no joy. All I am trying to do is POST to an NT server to pull back a page with a table of data for some screen scraping.
Here is what I have:
<?php
require("basic_sasl_client.php");
require("sasl.php");
require("http.php");
set_time_limit(0);
$http=new http_class;
$http->timeout=0;
$http->data_timeout=0;
$http->debug=1;
$http->html_debug=0;
$url="http://foo.bar.com/qpm/Results.CFM";
$user="spam";
$password="and_eggs";
$realm="nam";
$referer = "http://foo.bar.com/qpm/";
$authentication=(strlen($user) ? UrlEncode($user).":".UrlEncode($password)."@" : "");
$error=$http->GetRequestArguments($url,$arguments);
if($error!="") echo "\n\n==>Request Arguments Error: $error\n";
$arguments["AuthUser"]="spam";
$arguments["AuthPassword"]="and_eggs";
$arguments["Realm"]="nam";
$arguments["RequestMethod"]="POST";
$arguments["PostValues"]=array(
"Plant"=>"6000",
"OUTPUT"=>"Past12",
"top10_mnth"=>"na"
);
$arguments["Referer"]="http://foo.bar.com/qpm/";
echo "\n\n==>Opening connection to:", HtmlEntities($arguments["HostName"]), "\n";
flush();
$error=$http->Open($arguments);
if($error=="")
{
$error=$http->SendRequest($arguments);
if($error=="")
{
echo "\n\n==>Making Request:\n".HtmlEntities($http->request)."\n";
for(Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++)
{
$header_name=Key($http->request_headers);
if(GetType($http->request_headers[$header_name])=="array")
{
for($header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++)
echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n";
}
else
echo $header_name.": ".$http->request_headers[$header_name],"\r\n";
}
echo "\n";
if($arguments["RequestMethod"]=="POST")
echo "==>Request POST body: \n".$http->request_body."\n";
flush();
$headers=array();
$error=$http->ReadReplyHeaders($headers);
The reply that I see coming back from the ReadReplyHeaders (thanks to http->debug=1;) is a '140 Unauthorized'
S HTTP/1.1 401 Unauthorized
S Content-Length: 1656
S Content-Type: text/html
S Server: Microsoft-IIS/6.0
S WWW-Authenticate: Negotiate
S WWW-Authenticate: NTLM
S X-Powered-By: ASP.NET
S Date: Mon, 02 Mar 2009 16:56:54 GMT
It goes without saying that the username/pass/realm are valid for the target page.
What am I doing wrong in my attempt to use this super class against a Windows server?
Dave