1

I cant send my data in json format. In the server which i was using will accept only json body.

fetch('url', {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        FirstName: this.state.name,
        LastName: this.state.last,
        EmailAddress: this.state.emails,
        Phone: mobis
    })

}).then((response) => {
    alert(response);
    console.log(response)
}).catch((error) => {
    console.log(error);
    alert(error)
});

am using the above code to pass the data as json but its not going the response which am getting is [object Response]

by using console.log, i got a error is

Response {
    type: "cors",
    url: "https://api-in21.leadsquared.com/v2/LeadManagement.svc/Lead.Create?accessKey=u$raabd4c6e4e7953f215a7235495367a49&secretKey=a351cd31591c76f19642202ce97cd9417f1c46aa",
    redirected: false,
    status: 500,
    ok: false,
    statusText: "Internal Server Error",
    headers: Headers,
    bodyUsed: false
}

pls suggest me some code guys

Cata John
  • 1,371
  • 11
  • 19
hari
  • 11
  • 3

1 Answers1

0

You can also try this code

return fetch(HOSTNAME, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ variables: { input: data}})
  })
  .then((res) => {
    return res.json()
  })
  .then((payload) => {
    return payload
  }).catch((error) => {
    throw error
  })
Piyush Jain
  • 185
  • 1
  • 12