angularjs - Set-cookie in response not set for Angular2 post request -


when make put request in angular2, receive expected set-cookie in response. browser (tried both chrome , firefox) refuses set cookie.

instead when use angular 1 app making call same api endpoint, cookies set correctly.

the response headers are:

access-control-allow-credentials:true access-control-allow-origin:http://example.com allow:get, put, head, options content-type:application/json date:thu, 28 jan 2016 14:41:38 gmt p3p:policyref="http://www.example.com/p3p.xml", cp="non dsp cor cura tia" server:wsgiserver/0.1 python/2.7.6 set-cookie:sessionid=994wl49qfsizog5bqmt57sgx9q2toa25; expires=mon, 28-mar-2016 14:41:37 gmt; max-age=5183999; path=/ set-cookie:csrf=u7uqhpaphtsgykru6jfllft6noyahnms; domain=api.example.com; expires=thu, 26-jan-2017 14:41:38 gmt; max-age=31449600; path=/ vary:accept, cookie 

the backend programmed in django 1.8.

does experienced same thing or have suggestion how solve problem?

i seems cors-related issue. perhaps try set withcredentials attribute when executing http request.

this answer find out how that, cedric exbrayat's answer:

edit

you extend browserxhr:

@injectable() export class custombrowserxhr extends browserxhr {   constructor() {}   build(): {     let xhr = super.build();     xhr.withcredentials = true;     return <any>(xhr);   } } 

and override browserxhr provider extended:

bootstrap(appcomponent, [   http_providers,   provide(browserxhr, { useclass: custombrowserxhr }) ]); 

if need more hints cors, have @ link: http://restlet.com/blog/2015/12/15/understanding-and-using-cors/.

hope helps you, thierry


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -