itongx
April 22, 2024, 9:45am
1
Hi
I have made a custom header for my http client with reqwest but it seem add "accept": "/ " by default how could I get rid of this header ?
I test the code it always throw 411 error but if I test same request in application like Httpie it has no error
Sounds like we need more information on what the server side is expecting. When using HTTPie it will default to Accept: */*
just like reqwest.
You can change the accept header value in reqwest, before sending the HTTP request. Is there a specific "accept" value you need to send?
But maybe the cause of the 411 error is something different, I'd suggest comparing all the request headers between HTTPie and reqwest to see what might be different.
1 Like
itongx
April 23, 2024, 3:58am
3
here the header and body message for reqwest vs HTTPie. I only notice that accept header is different
POST
/GetPut?TYPE=GET
HTTP/1.1
{"content-length": "103", "content-type": "text; charset=ISO-8859-1", "host": "127.0.0.1", "user-agent": "reqwest", "accept": "/ "}
":HEADER\nTABLE=VERSION\nVERSION\nSTRING\n1.00\nTABLE=CURRENT_ATTRIBUTES\nSERIAL_NUM\nSTRING\nAB22D002000XX3Z28\n"
POST
/GetPut?TYPE=GET
HTTP/1.1
{"host": "127.0.0.1", "content-type": "text; charset=ISO-8859-1", "user-agent": "HTTPie", "content-length": "103", "connection": "close"}
":HEADER\nTABLE=VERSION\nVERSION\nSTRING\n1.00\nTABLE=CURRENT_ATTRIBUTES\nSERIAL_NUM\nSTRING\nAAB22D002000XX3Z28\n"
itongx
April 23, 2024, 5:08am
4
something strange that I test same code in python and it work as expected but always get 411 error when I test with rust
here a simple test python code
import requests
url = "http://127.0.0.1:3000/GetPut "
querystring = {"TYPE":"GET"}
payload = ":HEADER\nTABLE=VERSION\nVERSION\nSTRING\n1.00\nTABLE=CURRENT_ATTRIBUTES\nSERIAL_NUM\nSTRING\nAAB22D002000XX3Z28\n"
headers = {
"User-Agent": "request",
"Host": "127.0.0.1",
"Content-Type": "text/plain; charset=utf-8"
}
response = requests.request("POST", url, data=payload, headers=headers, params=querystring)
print(response.text)
itongx
April 24, 2024, 9:09am
5
found solution that need to build client manually from client builder and use title_header option
system
Closed
July 23, 2024, 9:10am
6
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.