Get not allowing data files json #1546
Replies: 2 comments 3 replies
-
Hi! Per the docs, which mention it under Requests Compatibility > Request body on HTTP methods:
Documented at the top of: https://www.python-httpx.org/api/ Example: >>> import httpx
>>> response = httpx.request('GET', 'https://httpbin.org/anything', json={'key': 'value'})
>>> response
<Response [200 OK]>
>>> response.json()
{'args': {},
'data': '{"key": "value"}',
'files': {},
'form': {},
'headers': {'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Content-Length': '16',
'Content-Type': 'application/json',
'Host': 'httpbin.org',
'User-Agent': 'python-httpx/0.17.0',
'X-Amzn-Trace-Id': 'Root=1-60622ae6-1d1cff9879dc8c341bd8fcdc'},
'json': {'key': 'value'},
'method': 'GET',
'origin': '72.32.180.176',
'url': 'https://httpbin.org/anything'} You can also create your own Request instances as documented here: https://www.python-httpx.org/advanced/#request-instances |
Beta Was this translation helpful? Give feedback.
-
A parameter having an undefined usage or semantics is not the same as it not being valid, from RFC7231 A payload within a GET request message has no defined semantics; From RFC7230 its very clear body with get is very much valid, where the standard explicitly points out one case where body is not valid and its in a response to a HEAD request. 3.3. Message Body The message body (if any) of an HTTP message is used to carry the
The rules for when a message body is allowed in a message differ for The presence of a message body in a request is signaled by a The presence of a message body in a response depends on both the |
Beta Was this translation helpful? Give feedback.
-
What if I want to test the behavior of a http server when receiving a body with get request. How should I do it ? This is no problem in requests library, they do support these parameters. I also need http/2 support.
From the HTTP 1.1 2014 Spec:
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
Beta Was this translation helpful? Give feedback.
All reactions