how to fix Refusal in Webservice Post

Asked

Viewed 197 times

0

When Sending the Post:

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "/CmisWebRequests.asmx/GetMessageResponse",
    data: dataToSend,
    dataType: "json",
    async: true,
    error: function(ex) {
        alert("EXCEPTION: " + JSON.stringify(ex));
    },
    success: function(resp) {
        var messageResponse = resp.d;
        $("#response").text(JSON.stringify(resp));
        $("#success").text(messageResponse.Success);
        $("#responseText").text(messageResponse.Response);
    },
    complete: function() {

    }
})

Fearful of denial

Response to preflight request doesn’t pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested Resource

How to give this permission to a particular requisitor ?

  • Permission must be performed in the back-end.. which language is using on the server?

  • The language used on the server is C#

2 answers

1


This is an existing protection in the Web Browser that blocks requests in Javascript (AJAX) that are not made from the same origin of your site.

This will happen if you are running a local Javascript and connecting to an external API (another site), if the server called is on a different port, if the host is different among other restrictions.

The solution is for the server to send a header

Access-Control-Allow-Origin: *

To allow requests to be made from other sources.

If you have no way to change the server (solution) you can try the tricks below:

  1. Use a proxy, which sends the above header, pq then you request the proxy and the proxy requests the API

  2. Manually remove CORS lock from your browser (you can do this in Developer mode)

  3. Use Internet Explorer or Chrome as Firefox is the hardest in CORS

You can tbem use JSONP, but then it depends on the support you have on the server (back to the source)

Good luck

0

In IIS the solution was to access the Request Filtering MENU and assign the POST verb in the HTTP Verbs tab.

  • That in the end ends up sending the header Access-Control-Allow-Origin: *

Browser other questions tagged

You are not signed in. Login or sign up in order to post.