2

I'm using fetch to send value to my server. my server is php. when I send my values with postman my server response as well.

but when I want to send my values with fetch I cannot get them from server side.

postman: enter image description here

my requestOption:

  const requestOptions = {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },

            body: JSON.stringify(parms)
        };

my values sent to server but I cannot get them like postman form-data.

parms is a object variable. like:

var parms = {};
parms['tok'] = '35345345';
StackedQ
  • 3,999
  • 1
  • 27
  • 41
S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254

1 Answers1

3

Just use formData as fetch body:

var formData = new FormData()
formData.append("tok", '35345345')
const requestOptions = {
        method: 'POST',
        headers: {
            'Accept': 'application/json'
        },

        body: formData
    };
StackedQ
  • 3,999
  • 1
  • 27
  • 41