当httpie和邮递员工作正常时,curl提出了错误的要求

时间:2019-01-29 07:45:18

标签: curl postman bad-request httpie insomnia

这是一个棘手的问题,使我感到困惑。 当我使用httpie或邮递员时,它工作正常,但由于curl收到了错误的请求。

这是我的代码:

http post http://myexaplesite.com/iSSC/wxapi/v1/token --debug  

HTTPie 1.0.2
Requests 2.20.1
Pygments 2.3.0
Python 3.7.2 (default, Jan 13 2019, 12:51:54) 

>>> requests.request(**{
    "allow_redirects": false,
    "auth": "None",
    "cert": "None",
    "data": {},
    "files": {},
    "headers": {
        "User-Agent": "HTTPie/1.0.2"
    },
    "method": "post",
    "params": {},
    "proxies": {},
    "stream": true,
    "timeout": 30,
    "url": "http://myexaplesite.com/iSSC/wxapi/v1/token",
    "verify": true
})

HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: application/json
Date: Tue, 29 Jan 2019 07:35:29 GMT
Proxy-Connection: keep-alive
Server: elb
Set-Cookie: f808689e40834f08ba52985b14d1842c=WyIyNDg2ODYyNjgiXQ; Expires=Wed, 30-Jan-19 07:35:29 GMT; Domain=myexaplesite.com; Path=/; HttpOnly
Transfer-Encoding: chunked

{
    "access_token": "just the token...",
    "expires_in": 3600,
    "token_type": "Bearer"
}


如您所见,邮递员也是如此。
但是当卷曲时:

curl -X POST http://myexaplesite.com/iSSC/wxapi/v1/token -i  

HTTP/1.1 400 Bad Request
Date: Tue, 29 Jan 2019 07:39:43 GMT
Content-Type: text/html
Content-Length: 0
Connection: keep-alive
Server: elb
Set-Cookie: f808689e40834f08ba52985b14d1842c=WyIyNDg2ODYyNjgiXQ; Expires=Wed, 30-Jan-19 07:39:43 GMT; Domain=myexaplesite.com; Path=/; HttpOnly
Proxy-Connection: keep-alive

我认为并没有太大区别,但是为什么不使用curl呢?


知道了原因,请求内容类型必须为Application / json,因此将curl更改为:

curl -d '' http://myexaplesite.com/iSSC/wxapi/v1/token -i

工作正常。

0 个答案:

没有答案