curl through authenticated proxy and authenticated http resource
Asked Answered
M

6

12

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.

Multifaceted answered 6/11, 2010 at 0:8 Comment(0)
F
21

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.

Flaunty answered 28/2, 2013 at 17:15 Comment(0)
R
6

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
Radiator answered 6/11, 2010 at 11:32 Comment(0)
D
3

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

Dimitri answered 6/11, 2010 at 0:33 Comment(0)
S
1

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
Shelashelagh answered 15/12, 2016 at 10:13 Comment(0)
R
1

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

$ curl --proxy socks5://proxyUser:proxyPass@proxy:port ...
Rightist answered 28/3, 2017 at 15:1 Comment(0)
B
0

I had this issue too, It doesn't resolved by just using --proxy-ntlm, Because I am working in a company with multiple network domains, Then by adding domain on my proxy's username:password it worked well:

curl -v --proxy-ntlm -U domain/username:password --proxy http://proxy:port https://www.google.com

Or in case of using general environment variable:

export proxy=http://domain%2Fusername:password@proxy:port
export http_proxy=%proxy%
export HTTP_PROXY=%proxy%
export https_proxy=%proxy%
export HTTPS_PROXY=%proxy%
export no_proxy=127.0.0.1,localhost,172.17.0.0,172.27.0.0

In case of using Windows please replace export with set

curl --proxy-ntlm https://www.google.com

Buskin answered 12/7 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.