Phr*_*ogz 3 mediawiki curl ntlm
tl; dr:对URL的HTTP请求可通过Chrome和Firefox使用,但无法使用curl。
详细资料:
我的公司使用MediaWiki作为Intranet Wiki。我的应用程序曾经使用以下命令成功使用cURL来获取有关页面的信息:
curl -s -k -u "username:password" "https://wiki.intranet/mainwiki/api.php?action=query&titles=SomePage&prop=info&format=xml"
但是,IT部门最近已将Wiki更改为使用某种“单点登录”系统。如果我现在请求该URL,则会通过以下位置获得一系列HTTP 302重定向:
/sso?request_uri=/mainwiki/api.php?action=query&titles=SomePage&prop=info&format=xmlhttp://wiki.intranet/sso/?request_uri=/mainwiki/api.php%3faction=query&titles=SomePage&prop=info&format=xmlhttps://wiki.intranet/sso/?request_uri=/mainwiki/api.php%3faction=query&titles=SomePage&prop=info&format=xml当我使用cURL请求最后一个URL时,我从服务器收到400(错误请求)响应。使用-I显示标题的参数,这里是:
> curl -S -k -I -u "username:password" "https://wiki.intranet/sso/?request_uri=/mainwiki/api.php%3faction=query&titles=SomePage&prop=info&format=xml"
HTTP/1.1 400 Bad Request
Date: Wed, 29 Apr 2015 20:47:49 GMT
Server: Apache/2.2.3 (CentOS)
Connection: close
Content-Type: text/html; charset=iso-8859-1
Run Code Online (Sandbox Code Playgroud)
但是,当我使用Google Chrome浏览器请求相同的URL时,会看到想要的结果!
我如何使用获取信息curl?
编辑:当我使用Firefox请求原始URL时,它也会经过相同的重定向,然后显示两个401(需要授权)状态。当我在Firefox中填写用户名/密码时,它会带我通过另一个重定向回到原始url,这时它会收到状态200响应以及所需的XML。
最后通过添加以下内容使它起作用:
curl -s -k-L --ntlm -c cookies.txt-u "user:pass" "originalurl"
请注意,有些页面建议您可以-u :在Windows上使用它来传递您的凭据。这对我没有用。
这在Windows上使用以下curl版本有效:
c:\> curl --version
curl 7.36.0 (x86_64-w64-mingw32) libcurl/7.36.0 OpenSSL/1.0.1c zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smtp smtps telnet tftp
Features: Largefile NTLM SSL libz TLS-SRP
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6097 次 |
| 最近记录: |