卷曲通过身份验证的代理和经过身份验证的http资源

use*_*427 9 rest curl

我想用oneliner做一个帖子(本例中是twitter).

如果我没有代理

curl -u user:pass -d status="message" http://twitter.com/statuses/update.xml
Run Code Online (Sandbox Code Playgroud)

工作得很好.

但是,当我在经过身份验证的代理服务器后面时却没有.

我试过了:

curl -X proxy:port -U proxyUser:proxyPass -u user:pass -d status="message" http://twitter.com/statuses/update.xml
Run Code Online (Sandbox Code Playgroud)

它让我跳了起来

代理不支持基本身份验证

所以你知道我做错了什么吗?

提前致谢.

小智 18

Cababunga的答案是正确的,但他们错过了另一种选择:--proxy-ntlm.某些代理无法正确授权--proxy-anyauth,因此理想情况下,您需要指定代理使用的身份验证方法.如果你跑步curl -v -U user:pass -x proxy:port --url http://www.google.com,你应该得到以下内容:

  • 即将连接()到代理[您的代理]端口[您的端口](#0)
  • 试试[IP] ......
  • 连接的
  • 连接到[您的代理]([IP])端口[您的端口](#0)
  • 建立到www.google.com:443的HTTP代理隧道
  • 代理使用Basic与用户'[user]'进行身份验证
  • 连接www.google.com:443 HTTP/1.1
  • 主持人:www.google.com:443
  • 代理授权:基本[乱码]
  • User-Agent:curl/[ver]([OS])libcurl/[ver] OpenSSL/[ver] zlib/[ver]
  • 代理连接:保持活跃
  • 需要HTTP/1.1 407代理验证
  • 代理验证:NEGOTIATE
  • 代理验证:NTLM

为您在Proxy-Authenticate参数中看到的任何内容添加一个标志,您应该很高兴.在此示例中,您将添加--proxy-ntlm标志.


twe*_*ak2 6

您可以将用户名/密码放在经过身份验证的资源的 URL 中,以避免出现额外的命令行复杂性。

http://username:password@twitter.com/statuses/update.xml
Run Code Online (Sandbox Code Playgroud)

此外,正如 cababunga 指出的那样,--proxy 快捷方式是小写的 x。

curl -x proxyaddr:port -U proxyUser:proxyPass -u user:pass -d status="message" http://twitter.com/statuses/update.xml
Run Code Online (Sandbox Code Playgroud)


cab*_*nga 3

尝试添加--proxy-digest--proxy-anyauth. 我认为要连接到代理,您应该使用小写字母-x(而不是-X)。