1

I am using the Fetch API built into ZombieJS at the moment and am currently trying to send a post request to a URL stored as a variable (in my code it is labeled as "link"). When I display the output of the post request, I see the status code is 404. The thing is I know the link exists and can verify through visiting it in a browser.

When I remove replace body: JSON.stringify(payload) with body: payload I get an error saying the body type is not supported. Can somebody tell me what I am doing wrong?

payload = {
        'name': 'test',
        'test2': 'abcd'
    }
response = await browser.fetch(link, {
    method: 'POST',
    credentials: 'same-origin',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(payload)
});
console.log(response);
Joundill
  • 6,828
  • 12
  • 36
  • 50
  • If you're getting a 404 error when posting to `link`, then the URL is either wrong or the server is returning a 404 when it should be a 405. What happens if you try a post request from curl or Postman? – Phil May 28 '20 at 02:06
  • Also, what **exactly** is the value of `link`? You can replace the domain name with `example.com` but please show the format of the value exactly as it appears in your script – Phil May 28 '20 at 02:25
  • @Phil It returns a code of 302 (which is ideal judging by Chrome network logs). The link variable is just the URL to a form – TreyWay2222 May 28 '20 at 02:34

0 Answers0