C
C
ceeed2021-12-30 13:09:39
JavaScript
ceeed, 2021-12-30 13:09:39

When I try to authorize, I get an error 400, what could be the problem?

I have a backend request to log in and get a token. When I make a request, I get a 400 error. I think I didn't pass the data correctly. When I try to make a request simply through the console, everything is fine for me - the token is returned to me. Here is an example of correct curl to get a token curl -X POST 127.0.0.1:8000/api/user/token --data "username=default&password=HLhm*Ppsv2q!AXG"
This is how I make a request to the server:
I pass the token and any password there ..

create(token) {
    try {
      return axios.post(`http://127.0.0.1:8000/api/user/token/`, {
        username: token,
        password: "1234",
      });
    } catch (e) {
      return e;
    }
  },
};

Here is what I get in response
61cd7e9e9317f384746950.png
61cd7eb0f34e9097731540.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-12-30
@ceeed

axios sends json, and from the console you send form-data.
Since you are making a request to the localhost, then you have access to the code. See what you expect.

A
alekssamos, 2022-01-03
@alekssamos

const formData = new FormData();
formData.append('username', 'token');
formData.append('password', '1234');
return axios.post(`http://127.0.0.1:8000/api/user/token/`, formData);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question