S
S
sharkdest2018-09-14 15:57:11
API
sharkdest, 2018-09-14 15:57:11

401 error when POST request React?

I don't know much about such requests, especially in React :)
Here is the React code:

import React from 'react';

export default class Request extends React.Component {

  componentDidMount() {
    var request = new XMLHttpRequest();
    var data = {
      'grant_type': "client_credentials",
      'user_name': "4"};

    request.open('POST', 'http://172.20.95.19/token', true);
    request.setRequestHeader('Authorization', 'Basic *********');
    request.setRequestHeader('Accept', 'application/json');
    request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    request.setRequestHeader('withCredentials', true);
    request.setRequestHeader("Access-Control-Allow-Origin", "*");
    request.send(data);
  }

  render() {
    return (
      <ul>
        <p>a</p>
      </ul>
    )
  }
}

Mistake:
OPTIONS http://172.20.95.19/token 401 ()

localhost/:1 Failed to load http://172.20.95.19/token: Response for preflight does not have HTTP ok status.

What am I doing wrong?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2018-09-14
@ulkoart

Perhaps the token is rotten or simply not correct.
401 indicates that authorization failed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question