Linux curl post请求出现错误417,但使用sudo成功?

我的服务部署在docker中,暴露的nginx端口为18082;服务端口为38087,我都试过了。

当我使用命令:

curl -i -X POST -H 'content-type: text/json' -d @post.json
http://127.0.0.1:18082/youtu/openliveapi/livedetectfour

返回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

但是当我在命令前面加上sudo时,它返回成功。 HTTP/1.1 100 Continue HTTP/1.1 200 OK Server: openresty/1.9.15.1

我真的做了搜索,知道当curl post超过1024字节时,它会首先发送expect 100-continue请求,如果服务器不支持该请求,则会返回417错误。

那么sudo是如何成功的,也许与nginx机制有关,我不太熟悉,谢谢。

点赞
用户2830850
用户2830850

由于您的公司设置了代理,代理可能已被插入到用户的 bash 配置文件中。您可以做三件事情:

更新 ~/.bash_profile 或 ~/.bashrc

从您的配置文件中删除代理,您就无需使用代理。

取消设置变量

在调用之前您可以取消设置变量:

unset http_proxy
unset https_proxy
curl -i -X POST -H 'content-type: text/json' -d @post.json \ http://127.0.0.1:18082/youtu/openliveapi/livedetectfour

对此错误调用进行变量清空

您可以仅为这次 curl 调用设置变量:

http_proxy= https_proxy= curl -i -X POST -H 'content-type: text/json' -d @post.json \ http://127.0.0.1:18082/youtu/openliveapi/livedetectfour
2017-08-16 05:03:47