I have some raw POST
and GET
requests in text files. For example:
GET /images HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Connection: close
I want to load this raw HTTP request from a text file and replay it programmatically. I'm thinking of reading the request line by line and set a header for each line with req.Header.Set("name", "value")
. But things get weird when I try to parse a POST
request that contains JSON body.
Is there a straightforward way to do this?