5

I have a RESTful service on a secured site. I can build a request just fine with the REST client in Firefox, but when I try to build it in code I get a 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 shows up in web developer tools in FF as:

Request-Headers:authorization,content-type

When what I need (from the rest client is FF) is:

Authorization:myAuthstring
Content-Type:application/json

Any clues as to what I am doing wrong?

**edit - turns out I am hitting the cross domain restriction. How does the rest client get around that?

Corey
  • 450
  • 3
  • 9
  • Ok, it looks like I am out of luck with this service as jsonp is not allowed. I don't know what else I can do. dataType: 'jsonp' returns an error. – Corey Sep 16 '11 at 23:40
  • You can't get around cors issue. Your API provider have to add that on their headers. I think it should be allow-cross-origin:* where * means allow all – qamar Jun 18 '15 at 00:39

1 Answers1

-1

you can pass contentType as an option to $.ajax

$.ajax({
    ...
    contentType: 'application/json'
});
Omer Bokhari
  • 57,458
  • 12
  • 44
  • 58