1

Can someone help with this code. When I pass a "post" request with basic auth status is 200 but nothing comes in response.With out auth the same code works

let username = 'username';
let password = 'password';
let headers = new Headers();
headers.set('Authorization', 'Basic ' + base64.encode(username + ":" + password));

fetch('https://sandbox.transactions.com', {
    method: 'post',
    body: JSON.stringify(body),
    headers: headers
  })
  .then(function(response) {
    return response.json();
  }).then(function(json) {
    console.log(json);

  }).catch(function(err) {
    console.log('There is an error ');
    res.status(500).send('There was an error while fetching');
  });
S1LV3R
  • 146
  • 3
  • 15
Hemanth
  • 13
  • 1
  • 4

1 Answers1

0

If the status is 200 that means that everything is ok. If you didn't get any data in return, that likely means the server has no data for you.

From https://httpstatuses.com/200:

Aside from responses to CONNECT, a 200 response always has a payload, though an origin server MAY generate a payload body of zero length.

S1LV3R
  • 146
  • 3
  • 15