Migrating from Bing Search API to Azure API Classic ASP

Answered Migrating from Bing Search API to Azure API Classic ASP

  • Friday, August 03, 2012 1:46 PM
     
     
    Would anyone have example code in Classic ASP? I seem to be having a problem passing the account key in the HTTP Request.
    401: The authorization type you provided is not supported. Only Basic and OAuth are supported
    • Edited by tonyPenn Friday, August 03, 2012 1:50 PM
    •  

All Replies

  • Friday, August 03, 2012 10:31 PM
     
     
    Can you paste your sample code here that can repro the problem?
  • Friday, August 03, 2012 10:49 PM
     
     
    I built my searchURL in the "Service Explorer" - works fine there and from a browser, authenticating normally.

    The problem seems to be here. I've tried the following:

    Set webreq = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
        webreq.open "GET", searchURL, false
        webreq.setRequestHeader "Authorization" ,"Basic " &  base64Encode(":" & MyNewKey)
        webreq.send

    The response is: 400: The provided format is not supported.

    Also tried:

    Set webreq = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
        webreq.open "GET", searchURL, false, sUsername, base64Encode(MyNewKey)
        webreq.send

    The response is: 401: The authorization type you provided is not supported. Only Basic and OAuth are supported

    I have tried a million other different variations of setting the request header.
  • Friday, August 03, 2012 11:12 PM
     
     

    Your first code block is correct.

    Set webreq = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
        webreq.open "GET", searchURL, false
        webreq.setRequestHeader "Authorization" ,"Basic " &  base64Encode(":" & MyNewKey)
        webreq.send

    The response is: 400: The provided format is not supported.

    400 means the query you are using is invalid. "The provided format is not supported." means the value you provider after $format is invalid.

    Can you share the query you were trying to make?

  • Saturday, August 04, 2012 1:49 PM
     
     Answered Has Code
    Right. I found the (stupid!) error in my query. I'm able to authenticate and get the data.Just need some help converting (I'm not following the documentation) this bit:
    estimatedTotalResultsCount = FormatNumber(webreq.responseXML.selectSingleNode("//*[local-name(.)='Total']").text,0,-1,-1,-1)        
    startIndex = webreq.responseXML.selectSingleNode("//*[local-name(.)='Offset']").text        
    Set results = webreq.responseXML.selectNodes("//*[local-name(.)='Result']")        
    endIndex = startIndex        
    For Each result in results  
    DocURL = result.selectSingleNode("*[local-name(.)='Url']").text            
    DocTitle = result.selectSingleNode("*[local-name(.)='Title']").text            
    DocSnippet = result.selectSingleNode("*[local-name(.)='Description']").text                       
    DocDisplayURL = result.selectSingleNode("*[local-name(.)='DisplayUrl']").text