question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot send request body in HTML request

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Richienbcommented, Jan 16, 2020

@sslotsky The first alpha should be released in March at the latest.

0reactions
sslotskycommented, Jan 16, 2020

Thanks, any idea when v3 will be shipped?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found