sharkdest2018-09-14 15:57:11
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', '', 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", "*");

  render() {
    return (

OPTIONS 401 ()

localhost/:1 Failed to load 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)
Artem, 2018-09-14

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