Skip to content

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

Description

@rjgotten

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions