设为首页收藏本站

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 787|回复: 0

PHP: curl with Windows Authentication

[复制链接]
发表于 2012-6-4 12:22:21 | 显示全部楼层 |阅读模式
本帖最后由 demo 于 2012-6-5 04:28 编辑

If one connects to an IIS 6 website configured with "Windows Authentication", the code bellow can be applied go get through. remember using the format for Windows domain user account!

Only if correct authentication credentials are given and the cURL option CURLOPT_HTTPAUTH is set to CURLAUTH_NTLM (CURLAUTH_ANY or CURLAUTH_ANYSAFE will not work!) the script terminates successfully and returns the content of the then authenticated request. The behaviour is not limited to requests to localhost (as in the sample code) and a request to an IIS 7 website with "Windows Authentication" will show the expected result (status 401 - no access violation). Test script:---------------
  1. <?php
  2. $curl = curl_init("http://localhost");
  3. //or: $curl = curl_init();
  4. //     $curl = curl_setopt($curl, CURLOPT_URL, "http://localhost");
  5. curl_setopt($curl, CURLOPT_VERBOSE, true);
  6. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  7. // In some bug version, if the authentication information are not given
  8. // in exactly this way the process will crash with
  9. // an access violation.
  10. //curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
  11. //curl_setopt($curl, CURLOPT_USERPWD, '<domain>/<user>:<password>');
  12. $data = curl_exec($curl);
  13. if(curl_errno($curl)) {
  14.    echo 'cURL error: ' . curl_error($curl)."\n";
  15. }
  16. curl_close($curl);
  17. php>
复制代码

Expected result:----------------
* About to connect() to localhost port 80 (#0)
*   Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
Host: localhost
Accept: */*

< HTTP/1.1 401 Unauthorized
< Content-Length: 1656
< Content-Type: text/html
< Server: Microsoft-IIS/6.0
< WWW-Authenticate: Negotiate
< WWW-Authenticate: NTLM
< Date: Tue, 20 Dec 2011 15:17:01 GMT
<
* Connection #0 to host localhost left intact
* Closing connection #0

Some special circumstances, refer to the follow link:

Bug #60576                        PHP cURL crash connecting to IIS6 website with NTLM authentication



您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )  

GMT-8, 2025-12-12 23:56 , Processed in 0.015677 second(s), 15 queries .

Supported by Best Deal Online X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表