user8416478 user8416478 -3 years ago 166
Linux Question

Linux curl post request and Error 417 but sudo success?

My service is deployed in docker,the exposed nginx port is 18082;service port is 38087,and I tried both.

while I use command

curl -i -X POST -H 'content-type: text/json' -d @post.json \

return 417

HTTP/1.1 417 Expectation failed
Server: squid/2.7.STABLE9
Date: Tue, 15 Aug 2017 11:57:04 GMT
Content-Type: text/html
Content-Length: 1436
X-Squid-Error: ERR_INVALID_REQ 0
X-Cache: MISS from SK-SQUIDDEV-118
X-Cache-Lookup: NONE from SK-SQUIDDEV-118:8080
Connection: close

But when I add sudo in the front,it return success.
HTTP/1.1 100 Continue
HTTP/1.1 200 OK Server: openresty/

I really do search and knew while curl post over 1024 bytes,it will first send

expect 100-continue.if server don't support that request, it will return 417 error.

then how can sudo succsess,maybe It is related to nginx mechanism,I'm not familiar with that.thanks.

Answer Source

Since you are using proxy in your corporate setup and the proxy might be insert in your user's bash profile. You can do 3 things

Update ~/.bash_profile or ~/.bashrc

Remove the proxy from your profile and you won't need the proxy

Unset the variables

You can unset the variables before the call

unset http_proxy
unset https_proxy
curl -i -X POST -H 'content-type: text/json' -d @post.json \

Blank the variables for the call

You can set the variables just for that one curl call

http_proxy= https_proxy= curl -i -X POST -H 'content-type: text/json' -d @post.json \
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download