I am using the python requests library and want to send a request with the header “Transfer-Encoding:chunked”.
Unfortunately, I cannot get it to work.
Even if I explicitely set the header, it is not used in the request.
Below is my code for testing and the corresponding captured request:
import requests
url = 'http://[replaced]/test.php'
def data_chunks():
yield b'8rn'
yield b'search=1rn'
yield b'0rn'
response = requests.post(url,data=data_chunks(), headers={"Content-Type":"application/x-www-form-urlencoded","Transfer-Encoding":"chunked"}, proxies={"http":"http://127.0.0.1:8080"})
POST /test.php HTTP/1.1
Host: [replaced]
User-Agent: python-requests/2.28.1
Accept-Encoding: gzip, deflate
Accept: /
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 168
search=1
0
If I do not set the “Transfer-Encoding” header it is not used and even if I explicitly set the “Transfer-Encoding” header like in the example above it is not used.
The requests library always seems to put a “Content-Length” instead.
What am I supposed to do?