Modify send content #2039
|
I have an HTTPX client. # client
import httpx
client = httpx.Client()
def __req(request: httpx.Request):
request._content = b'Hello'
client.event_hooks['request'].append(__req)
response = client.post(
'http://192.168.8.184:10240/test',
data=b'Test'
)
client.close()# server
from fastapi import FastAPI, Request
app = FastAPI()
@app.post('/test')
async def test(request: Request):
'''
'''
print(await request.body())
return {'message': 'Hello'}# output
INFO: Application startup complete.
b'Test'
INFO: 192.168.8.184:34930 - "POST /test HTTP/1.1" 200 OK
Translated with www.DeepL.com/Translator (free version) |
Answered by
lovelydinosaur
Jan 21, 2022
Replies: 1 comment 4 replies
|
Working with private implementation details like that isn't going to be a good route to go down - you shouldn't expect it to work, and even if it did, you might well find that some future version broke it. It's not clear what actual behaviour you're trying to implement, and why. We'd need a clearer idea of that in order to help you find a better approach. |
4 replies
Answer selected by
mangfu26
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working with private implementation details like that isn't going to be a good route to go down - you shouldn't expect it to work, and even if it did, you might well find that some future version broke it.
It's not clear what actual behaviour you're trying to implement, and why. We'd need a clearer idea of that in order to help you find a better approach.