0
    fetch(url, {
      method: 'post',
      headers: {
        "Content-type":
      },
      body: 'bar= foo& lorem=ipsum'

    })

Should it be?

A) application/x-www-form-urlencoded; charset=UTF-8

B) text/html; charset=utf-8

C) application/json; charset=UTF-8

D) Content-Type: multipart/form-data; boundry=something

I've just started to learn JavaScript and APis. While looking at MDN docs I found there are different options to put in the headers. Just confused about which one to use?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Jojo
  • 71
  • 1
  • 2
  • 5
  • 1
    Depends entirely upon what the server expects/cares about. urlencoded form data seems most appriopriate here based on the request body I think. – CollinD Oct 14 '22 at 22:46
  • 2
    The body format `name=value&name=value` is Url-encoded. – Barmar Oct 14 '22 at 22:50

1 Answers1

2

A sequence of key=value parameters separated by & is the URL-encoded format of parameters. So A is the correct answer.

Barmar
  • 741,623
  • 53
  • 500
  • 612