How to set request header lines

I have a RESTful service on a secure site. I can create the request just fine with the REST client in Firefox, but when I try to build it in code, I get 401. Here is my code

(function() {
                $.ajax({
                    url : "https://myrestsite",
                    type : "GET",
                    //beforeSend: function (req){
                    //  req.setRequestHeader("Authorization","myauthstring");
                    //  req.setRequestHeader("Content-Type", "application/json");
                    //},                        
                    headers : {
                        "Authorization" : "myauthstring",
                        "Content-Type" :  "application/json",
                    },      
                    success : function (){alert('we got here')}
                });
            })();

This is displayed in the web developer tools in FF as:

Request-Headers:authorization,content-type

When I need (from the rest of the FF client):

Authorization:myAuthstring
Content-Type:application/json

Any tips on what I'm doing wrong?

** edit - it turns out that I click the cross-domain restriction. How is the client still handling this?

+5
source share
1 answer

you can pass contentType as an option to $ .ajax

$.ajax({
    ...
    contentType: 'application/json'
});
-1
source

All Articles