I am trying to connect to my newly created Bing Search API using Java in Android Studio.
When I execute the connection.getInputStream()
statement, it returns a 401 error saying "Acces Denied".
The same error is returned when I provide a wrong suscription key on purpose. However, I am sure that the suscription key that I am using is right, as I am copying and pasting it from the Azure control panel, and it is from the only suscription I have (a trial one).
I need help, please. Thanks.
URL url = new URL("https://api.bing.microsoft.com/v7.0/search" + "?q=" + URLEncoder.encode(input, "UTF-8")); HttpsURLConnection connection = (HttpsURLConnection)url.openConnection(); connection.setRequestProperty("Ocp-Apim-Subscription-Key", "( censored )"); try{ InputStream stream = connection.getInputStream(); }catch (Exception e){ //java.io.FileNotFoundException: https://api.bing.microsoft.com/v7.0/search?q=... int c = connection.getResponseCode(); // = 401 String s = connection.getResponseMessage(); // = "Acces Denied" }
https://stackoverflow.com/questions/67372791/bing-search-api-getting-401-acces-denied-error-while-using-the-right-suscriptio May 04, 2021 at 12:52AM
没有评论:
发表评论