curl - 使用 curl 通过 SSO 重定向获取 MediaWiki 页面信息

标签 curl mediawiki 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=xml
  • http://wiki.intranet/sso/?request_uri=/mainwiki/api.php%3faction=query&titles=SomePage&prop=info&format=xml
  • https://wiki.intranet/sso/?request_uri=/mainwiki/api.php%3faction=query&titles=SomePage&prop=info&format=xml

当我使用 cURL 请求最后一个 URL 时,我从服务器收到 400(错误请求)响应。使用 -I 参数显示 header ,这里是:

> 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

但是,当我使用 Google Chrome 请求相同的 URL 时,我看到了我想要的结果!

如何使用 curl 获取信息?


编辑:当我使用 Firefox 请求原始 URL 时,它也经过相同的重定向,然后显示两个 401(需要授权)状态。当我在 Firefox 中填写用户名/密码时,它会通过另一个重定向返回到原始 url,此时它会收到状态 200 响应以及我想要的 XML .

最佳答案

最后通过添加以下内容使其工作:

curl -s -k-L --ntlm -c cookies.txt-u "user:pass""原始网址”

请注意,某些页面建议您可以在 Windows 上使用 -u : 来传递您的凭据。这对我不起作用。

这在 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

关于curl - 使用 curl 通过 SSO 重定向获取 MediaWiki 页面信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29954481/

相关文章:

curl - 如何为 dns 缓存设置 TTL 以及如何清除 curl 缓存

namespaces - mediawiki 删除了命名空间和伪命名空间

java - Android:NTLM 身份验证、ksoap 和持久连接

java - 尽管我使用正确的 OAuth token ,但尝试从 Java 应用程序访问托管的 SharePoint 2013 会给我 401

azure - Azure ASE 中的应用程序需要使用 NTML Web 服务进行身份验证

php - Centos 6.6 CURL 在连接到某些 SSL 站点时返回错误

curl - curl -v 和 curl -I 有什么区别

c# - WebRequest 相当于 `curl -X DELETE ...`

php - 将用户添加到 MediaWiki 的脚本

javascript - MediaWiki 上的用户自定义 JavaScript 可以调用 Lua 模块吗?