Threaded View

  1. #1
    Sencha User
    Join Date
    Jun 2012
    Posts
    16
    Answers
    1
    Vote Rating
    0
    fsuarez is on a distinguished road

      0  

    Default Answered: Cant POST JSON data to https REST API via Ext.Ajax while GET is possible

    Answered: Cant POST JSON data to https REST API via Ext.Ajax while GET is possible


    Hi,

    Im trying to use Ext.Ajax to post some data as JSON to a Rest API server. Its a cross domain request but the server uses CORS. Im able to do GET and retrieve JSON data with no problems but when trying to do a POST it fails. In the following code I try to do a login
    Code:
         login = function (callerInstance, user, pass, onLogin) {
            Ext.Ajax.setUseDefaultXhrHeader(false); 
            var url = SERVER + "login";
            var data = {};
            data.username = user;
            data.password = pass;
            Ext.Ajax.request({
                url: url,
                method: 'POST',
                jsonData: data,
                success: function(response, opts) {
                    console.log(TAG + 'responseText: ' + response.responseText);
                    onLogin.call(callerInstance, LOGGED_IN, response.responseText);
                },
                failure: function(response, opts) {
                    console.log(TAG + 'server-side failure with status code ' + response.status);
                    console.log(TAG + 'responseText: ' + response.responseText);
                    onLogin.call(callerInstance, NOT_LOGGED_IN, response.responseText);
                }
            });
        };
    The result of this is
    Code:
    HosRestApi: server-side failure with status code 0 
    And if I comment out the jsonData line, I get this error:
    Code:
    
    HosRestApi: server-side failure with status code 500
    HosRestApi: responseText: {"errorText":"Internal Server Error: Object reference not set to an instance of an object."}
    So the server is trying to process the request but failing as there is no login data.
    So Im not sure why is the first error I mentioned happening or where is happening, or whats the problem.
    The URL is https, does that makes any difference?
    Please help me on this one!

  2. It was a CORS problem after all. To get my server supporting CORS Im using the following configuration:

    Code:
    <customHeaders>
    	<add name="Access-Control-Allow-Origin" value="*" />
    	<add name="Access-Control-Allow-Methods" value="GET, POST, DELETE, OPTIONS" />
    	<add name="Access-Control-Allow-Headers" value="origin, content-type, x-requested-with" />
    </customHeaders>
    In the web.config file (its a IIS server). I hope this helps someone

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi