Reputation: 88
I'm trying to get contents of a SSL ASPX page using cURL, here's my code:
$ourFileName = "cookieFIle.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
function curl_get($url) {
$ch = curl_init();
$options = array(
CURLOPT_HEADER => 1,
CURLOPT_URL => $url,
CURLOPT_USERPWD => 'XXX:XXX',
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
CURLOPT_HTTPHEADER => $header,
CURLOPT_COOKIESESSION, true,
CURLOPT_COOKIEFILE, "cookieFIle.txt",
CURLOPT_COOKIEJAR, "cookieFIle.txt"
);
curl_setopt_array($ch, $options);
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
echo curl_get('https://somepage.com/intranet/loginprocess.aspx');
And whenever I perform the code I receive this:
Header:
HTTP/1.1 401 Unauthorized
Content-Length: 1656
Content-Type: text/html
Server: Microsoft-IIS/6.0
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-UA-Compatible: IE=EmulateIE8
Date: Sat, 16 Nov 2013 19:05:18 GMT
Message:
You are not authorized to view this page
You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.
The login and password are 100% correct and url is too. OpenSSL is installed on the RaspverryPI I'm using and cURL is enabled in php.ini
The loginprocess.aspx redirects you to studenthome.aspx after authorisation is complete, but I think the problem is in the authorisation itself.
Upvotes: 1
Views: 1081
Reputation: 19945
You are trying to connect with basic authentication, while the server is requesting integrated windows authentication (NTLM).
Use the option CURLAUTH_NTLM.
You should not set cookiesession to true. From the manual :
TRUE to mark this as a new cookie "session". It will force libcurl to ignore all cookies it is about to load that are "session cookies" from the previous session. By default, libcurl always stores and loads all cookies, independent if they are session cookies or not. Session cookies are cookies without expiry date and they are meant to be alive and existing for this "session" only.
Your code also has typos. It should read like this :
CURLOPT_HTTPHEADER => $header,
CURLOPT_COOKIEFILE => "cookieFIle.txt",
CURLOPT_COOKIEJAR => "cookieFIle.txt"
);
Upvotes: 3