Cannot send request body in HTML request
See original GitHub issueI’m currently using node-fetch to request HTML pages, parse them, and display some of their content on the page that I’m serving. This works fine for GET requests, but I also need to support a form POST, and when I try to add the request body, it doesn’t come across. I’ve tried a couple different ways, shown below. Your docs seem to indicate that these should both be possible, but in both cases, the request body is empty when the other party receives it.
Forgive me if this is a dupe, I couldn’t tell if this was the same thing being discussed in this issue or in the related PR
JSON.stringify
const response = await fetch(`${p.address}/${p.version}${req.path}`, {
method: req.method,
body: JSON.stringify(req.body),
headers: {
Accept: 'text/html',
'Content-Type': 'x-www-form-urlencoded',
},
});
URLSearchParams
const response = await fetch(`${p.address}/${p.version}${req.path}`, {
method: req.method,
body: formData,
headers: {
'Transfer-Encoding': 'chunked',
Accept: 'text/html',
'Content-Type': 'x-www-form-urlencoded',
},
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Unable to send request body in Http GET method on angular 10
Our api server need empty request body object in GET request. Note: I dont want to use POST method for send request body....
Read more >HTTP/1.1: Header Field Definitions
If an Accept-Encoding field is present in a request, and if the server cannot send a response which is acceptable according to the...
Read more >Add a Request Body to a POST Request | API Connector
If your POST request isn't working, a likely cause is a mismatched content type. Try adding in a content type into the header...
Read more >Building requests | Postman Learning Center
If your request doesn't require body data, auth, or headers, select Send. Otherwise, set up your body, auth, and headers. Sending body data....
Read more >What is HTTP GET Request Method? - ReqBin
No, HTTP GET requests cannot have a message body. But you still can send data to the server using the URL parameters. In...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sslotsky The first alpha should be released in March at the latest.
Thanks, any idea when v3 will be shipped?