Skip to content

Add Content-Type application/json for XHR #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

joel-airspring
Copy link

The content type should be set to JSON since it's a JSON payload.

Some servers will not interpret it as JSON otherwise. For example, node's express server middleware will not parse the body and convert it to an object.

This is against branch 2.x since master does not have the XHR feature yet. Let me know if I should resubmit against a different branch.

Thanks!

@benvinegar
Copy link
Contributor

This is against branch 2.x

Looks like you accidentally targeted master in GitHub. Unfortunately GitHub doesn't let you change the target branch, so you'll have to re-open this as a new PR against 2.x.

@benvinegar benvinegar closed this Dec 4, 2015
@benvinegar
Copy link
Contributor

Oh, and @mattrobenolt reminds me – we can't accept this patch.

If we specify this Content-type header value, browsers will trigger an OPTIONS preflight request as part of CORS. It also means this request will not work at all in IE8 and IE9, since they have more limited CORS implementations.

more here: http://stackoverflow.com/a/12320736

@grabbou
Copy link

grabbou commented Mar 11, 2016

That however breaks on latest React / Android - adding console.log in react-native plugin gives me status: '0', message: 'Payload is set but no content-type header specified' which is coming from native java module.

@mattrobenolt
Copy link
Contributor

I assume we could do this for React Native without triggering the OPTIONS preflight request?

@grabbou
Copy link

grabbou commented Mar 11, 2016

I've decided to open an issue regardless, haven't expected such quick answer! ( #526 ) I am not sure if the above concerns also apply to React Native since native code is involved on both platforms (e.g. okhttp on android)

@mattrobenolt
Copy link
Contributor

Totally. My hunch is its ok for us to do it for React Native, but @benvinegar will need to confirm. Thanks for letting us know. :)

@benvinegar
Copy link
Contributor

Yeah React Native basically ignores cross-origin rules. We can implement this in the React Native transport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants