S.M_Emamian
S.M_Emamian

Reputation: 17383

How to send values like form-data postman - react js

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';

Upvotes: 2

Views: 2588

Answers (1)

StackedQ
StackedQ

Reputation: 4139

Just use formData as fetch body:

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

        body: formData
    };

Upvotes: 3

Related Questions