Reputation: 309
I am trying to access a web-Api (Prestashops Web API to be exact) and fetch seems to have a problem with an url in this format : http://[email protected]
. In both Chrome and Postman everything works perfectly fine but using the fetch-API I always get an 401
Error.
Here is my Typescript Code :
public fetchData() {
fetch("http://[email protected]").then((response : Response)=>{
response.text().then((text : string) =>console.log(text));
})
Upvotes: 2
Views: 299
Reputation: 88286
The Fetch API doesn’t allow a URL in the form http://[email protected]
to be used in requests. Specifically, it doesn’t let you to use an "@
" character before the hostname.
If you use such a URL, it’s interpreted as providing username/password credentials, and the Fetch spec requires browsers to throw a TypeError
(and thus to halt the request):
The
Request(input, init)
constructor must run these steps:
…
If parsedURL includes credentials, then throw aTypeError
.
The only solution is to not put credentials in the request URL in the way (that is, don’t have a "@
" character before the hostname in the request URL).
Upvotes: 1