Answered regarding Azure implementation

  • Wednesday, July 25, 2012 11:49 AM
     
     

    Existing:

     var requestStr = "http://api.bing.net/json.aspx?"+query+ "JsonType=callback", "JsonCallback=?";

    $.ajax({
                    type: "GET",
            url: requestStr,
                    dataType: "jsonp",
                    cache: true,
                    timeout: 5,
                    success: function(msg) {  i show the results; },error:function(msg){alert(msg.d)}

    New code:

     var arr=query+ other attributes;

      var requestStr ="https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Web"+arr;

       $.ajax({
                    type: "GET",
                    url: requestStr,
                    dataType: "json",
                    context:this,
                    cache: true,
                    timeout: 5,
                    beforeSend: function(xhr){
                        xhr.setRequestHeader('Authorization', 'Basic username:azurekey');
                 },success: function(msg) {  i show the results; },error:function(msg){alert(msg.d)}

    I always end up in getting the error message :  kindly  suggest regarding my implementation.

All Replies

  • Thursday, July 26, 2012 2:48 AM
    Moderator
     
     

    Hi,

    Do you got any details message about the error? I suggest you use Fiddler 2 to capture the send request get more infomation.

    Another thing is check if you ever use Base 64 to encode your Azure Marketplace key.

    Hope this helps.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

    • Marked As Answer by febrookbee Thursday, July 26, 2012 7:57 AM
    • Unmarked As Answer by febrookbee Thursday, July 26, 2012 7:57 AM
    •  
  • Thursday, July 26, 2012 7:59 AM
     
     

    Great! thanks for your reply,  i have tried the following and it work. how ever, is there is any way to avoid the user name ie my emailaddress  not to show up in the code:

     var accountKey = "xxxx..........................";
       function setHeader(xhr) {
           xhr.setRequestHeader('Authorization', 'Basic'+'febrookbee@yahoo.co.in'+$.base64.encode(':'+accountKey));
       }
       var requestStr ="https://api.datamarket.azure.com/Bing/SearchWeb/Web?Query=%27i90%27";
       // make the call

       $.ajax({
               type: 'GET',
                   url: requestStr,
                   dataType: "json",
                   context: this,
                   beforeSend: setHeader,
                   success: function(data,status){
                   alert('posted!!!!');
               },
                   error: function() {alert('not working');},

                   });


    Murali

  • Thursday, July 26, 2012 8:24 AM
    Moderator
     
     

    Hi Murali,

    Actually username property is not required, you need only add password as the authorization header.

    For example, use Base 64 encode ':' + '<Your key>' in JQuery code, the request will still works.

    BR,

    Arwind


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework

  • Thursday, July 26, 2012 11:16 AM
     
     

    Thanks arwind,

      the following authentication works. how ever it returns me a null value which is eating my head!.....

     xhr.setRequestHeader('Authentication','Basic'+ $.base64.encode(accountKey));

     $.ajax({  
               url: requestStr,
               dataType: "json",
               context: this,
               beforeSend: setHeader,
            
               success: function(data,status){
               alert(data);   //  i get always a null data ..........!!
           },
               error: function() {alert('not working');},
           
               });



    Murali

  • Thursday, July 26, 2012 4:19 PM
     
     

    Thanks guys!..  here if the fix for it.

    This makes the code to work:  xhr.setRequestHeader('Authorization', 'Basic '+encodedkey);

      var wshost = 'https://api.datamarket.azure.com/Bing/SearchWeb/Web';

      var wssearchparam=query and other attributes for search!

     //send request to bing api
        $.ajax({
                type: 'GET',
                    url: wshost,
                    data: wssearchparam,
                    dataType: "json",
                    context: this,
                    beforeSend: function(xhr){
                    xhr.setRequestHeader('Authorization', 'Basic '+encodedkey);
                },
                    success: function(data){
                    searchResults = data.d.results;
                    alert(searchResults);
                    alert(searchResults.length);
                    for (var i = 0; i < searchResults.length; i++) {
                    var object = searchResults[i];
                    for (property in object) {
                    var value = object[property];
                    alert(property + "=" + value);
                     }
                    }
                }
            });


    Murali

    • Marked As Answer by febrookbee Thursday, July 26, 2012 4:23 PM
    • Unmarked As Answer by febrookbee Friday, July 27, 2012 8:07 AM
    •  
  • Monday, July 30, 2012 12:35 PM
     
     Answered
    It works fine with Firefox browser but in IE, it fails and the error message say   permission deined for the request.  kindly suggest!

    Murali

    • Marked As Answer by febrookbee Tuesday, August 07, 2012 6:58 AM
    •  
  • Tuesday, August 07, 2012 6:59 AM
     
     Answered
    If we add a proxy for the azure api url in apache. it works fine in IE. also.

    Murali

    • Marked As Answer by febrookbee Tuesday, August 07, 2012 6:59 AM
    •