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) |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
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.