Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set withCredentials to the new ES6 built-in HTTP request API : Fetch

How to set withCredentials=true to fetch which return promise. Is the following correct :

fetch(url,{    method:'post',    headers,    withCredentials: true }); 

I think the MDN documentation talked about everything about http-requesting except this point: withCredentials

like image 828
Abdennour TOUMI Avatar asked Nov 11 '16 07:11

Abdennour TOUMI


People also ask

Is fetch part of es6?

No, fetch is not part of them. They only define the language (syntax and semantics) and a few builtin objects.

How do I post using fetch API?

POST request using fetch API:To do a POST request we need to specify additional parameters with the request such as method, headers, etc. In this example, we'll do a POST request on the same JSONPlaceholder and add a post in the posts. It'll then return the same post content with an ID.

What is fetch API in JavaScript?

The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.


1 Answers

Got it here :

  credentials: 'include' 

and not

  withCredentials: true 
like image 101
Abdennour TOUMI Avatar answered Sep 17 '22 13:09

Abdennour TOUMI