开发者

curl through authenticated proxy and authenticated http resource

开发者 https://www.devze.com 2023-01-24 05:53 出处:网络
I want to do a post (twitter in this case) with a oneliner. If I don\'t have proxy curl -u user:pass -d status=\"message\" http://twitter.com/statuses/update.xml

I want to do a post (twitter in this case) with a oneliner.

If I don't have proxy

curl -u user:pass -d status="message" http://twitter.com/statuses/update.xml

works perfectly.

But when I am behind a authenticated proxy it doesn't.

I had tryied:

开发者_运维百科
curl -X proxy:port -U proxyUser:proxyPass -u user:pass -d status="message" http://twitter.com/statuses/update.xml

That it jump me with an

proxy do not support basic auth

So do you know what I am doing wrong?

thanks in advance.


Cababunga's answer is correct, but they're missing another option: --proxy-ntlm. Some proxies won't authorize correctly with --proxy-anyauth, so ideally you'll want to specify the authentication method that your proxy uses. If you run curl -v -U user:pass -x proxy:port --url http://www.google.com, you should get something along the lines of the following:

  • About to connect() to proxy [your proxy] port [your port] (#0)
  • Trying [IP]...
  • connected
  • Connected to [your proxy] ([IP]) port [your port] (#0)
  • Establish HTTP proxy tunnel to www.google.com:443
  • Proxy auth using Basic with user '[user]'
  • CONNECT www.google.com:443 HTTP/1.1
  • Host: www.google.com:443
  • Proxy-Authorization: Basic [gibberish]
  • User-Agent: curl/[ver] ([OS]) libcurl/[ver] OpenSSL/[ver] zlib/[ver]
  • Proxy-Connection: Keep-Alive
  • HTTP/1.1 407 Proxy Authentication Required
  • Proxy-Authenticate: NEGOTIATE
  • Proxy-Authenticate: NTLM

Add a flag for whatever you see in the Proxy-Authenticate parameter and you should be good to go. In this example, you would add the --proxy-ntlm flag.


You may be able to put the username/password in the URL for the authenticated resource to avoid having extra command line complications.

http://username:password@twitter.com/statuses/update.xml

also, the --proxy shortcut is a lowercase x, as cababunga pointed out.

curl -x proxyaddr:port -U proxyUser:proxyPass -u user:pass -d status="message" http://twitter.com/statuses/update.xml


Try to add --proxy-digest or --proxy-anyauth. And I think to connect to proxy you should use lower case -x (not -X).


I managed to perform this with the help of the Micah's answer here:

this is the command I got at the end to access a BitBucket repo:

curl  -u userBitbucket:PwdBitBucket -U userProxy:pwdProxy -x address_proxy:port:proxy --proxy-ntlm http://host:port/projects/project/repos/repo/browse/file


You may want to try using SOCKS v5 instead of v4:

$ curl --proxy socks5://proxyUser:proxyPass@proxy:port ...
0

精彩评论

暂无评论...
验证码 换一张
取 消