Skip to content
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

Cannot perform crossdomain POST with application/json content type #77

Open
rjgotten opened this issue Jun 27, 2022 · 0 comments
Open

Comments

@rjgotten
Copy link

Assume given a third-party API not under the developer's control which explicitly only responds to Content-Type: application/json and which returns a 415 - Unsupported media type status code for all other content types.

Actual result
It is impossible to succesfully make a request to such an API using can-ajax.

The library tries to protect the user from executing a CORS preflight request and will in all cases where it deems the HTTP method allows for a 'simple CORS request', override the Content-Type header with application/x-www-form-urlencoded content type.

There is no way to override this and implementing such a request with can-ajax is a complete no-go.
It is necessary to drop the abstraction layer and work directly with the raw XmlHttpRequest or fetch browser APIs.

Expected result / Mitigation
There is an override escape-hatch possible for the above scenario:
if the developer specifies an explicit contentType, then that means 'hands off' and it gets used without any magic auto-assist.

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

No branches or pull requests

1 participant