Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl through authenticated proxy and authenticated http resource

Tags:

rest

curl

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.

like image 298
user2427 Avatar asked Nov 06 '10 00:11

user2427


2 Answers

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.

like image 169
Micah Avatar answered Oct 06 '22 19:10

Micah


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:[email protected]/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
like image 30
tweak2 Avatar answered Oct 06 '22 20:10

tweak2