New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--json
with no request items omits body entirely instead of providing empty object
#218
Comments
This is more or less intentional, it matches HTTPie: $ http --offline --json post :
POST / HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 0
Content-Type: application/json
Host: localhost
User-Agent: HTTPie/2.6.0
It does seem wrong, so maybe we should change it. I've opened httpie/cli#1263. (The current best way to send an actual empty JSON object is |
Thank you for opening the upstream issue |
Given that the upstream issue has been closed with no action, I think we should go with @blyxxyz's solution i.e. don't set Content-Type unless there is a JSON body.
|
If I do a request like
xh -p HBhb POST http://example.com --json
the outgoing request looks likeNotice the complete lack of any body despite
Content-Type: application/json
. This is an invalid JSON body.In the absence of request items, passing
--json
should pass the body as{}
.The text was updated successfully, but these errors were encountered: