google chrome - Got 400 error for pre-flight options CORS token request from OWIN-based WebAPI -
it strange.
i tried make cors request webapi2 (owin-based) gain authentication token.
it fails every other times. 1st request fails, 2nd request go through. , 3rd fails, 4th go through.
i don't understand why working half of times.
i check browser request (chrome).
the 1 got failed goes options method. 1 went through goes post.
but use post method headers 'content-type': 'application/x-www-form-urlencoded'
so guess question why sometime chrome/fire fox send preflight request sometime doesn't.
btw, works totally fine in ie.
you correct both chrome , firefox use preflight options request. so, prior executing post, chrome/firefox sends request options verb. if not receive response server tells browser allowed send cross domain request, you'll error , subsequent post not post.
you have enable options in web.config (or using 1 of approaches listed in article): http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
for web.config try:
<httpprotocol> <customheaders> <add name="access-control-allow-origin" value="*" /> <add name="access-control-allow-methods" value="get, post, options,put"/> <add name="access-control-allow-headers" value="content-type, accept"/> </customheaders>
ie has been slow in adopting cors standards, that's why ie working fine without options enabled.
Comments
Post a Comment