0

I would like to reproduce the behavior of this cURL request :

➜  % curl --data "" https://api.t411.ch/auth
{"error":"User not found","code":101}

In this case, the server send me back JSON.

The code I use in Javascript is :

fetch('https://api.t411.ch/auth/', {
    method: 'POST'
}).then(response => {
  return response.json();
}).then(datas => {
  console.log(datas);
});

With that, I get a parsing json error, so, I decided to return response.text() instead of response.json()

The console.log(datas) prints : string(5) "1.2.4" Service 'view' wasn't found in the dependency injection container

It's the same string that I get when I access to the url : https://api.t411.ch/auth with my browser (GET request).

That means that my javascript code send a GET request, even with the method: 'post'

What am I doing bad ?

PS: I think it's not related at all, but I use es6/jsx transpiled by babel in an electron project.

Thanks

2
  • Word of warning: this is experimental javascript and poorly supported. Don't use it for anything other than fiddling around, just use a standard XMLHttpRequest. Commented Jul 24, 2016 at 22:16
  • Getting a security warning when clicking that link. Commented Aug 24, 2019 at 14:36

1 Answer 1

1

Your code is trying to POST to https://api.t411.ch/auth/. It should be https://api.t411.ch/auth instead. This should work fine:

fetch('https://api.t411.ch/auth', {
    method: 'POST'
}).then(response => {
  return response.json();
}).then(datas => {
  console.log(datas);
});
Sign up to request clarification or add additional context in comments.

1 Comment

oh, thanks ! And say that I spent over two hours for a "/".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.