Elnatan Derech
Elnatan Derech

Reputation: 1037

Bing web search api v5.0 returns "Resource not found" from Android app

I queried the Bing web search api with the "food" word.

This is the code:

    Ion.with(this)
            .load("https://api.cognitive.microsoft.com/bing/v5.0/search")
            .setHeader("Ocp-Apim-Subscription-Key", "xxxxxxxxxxxxxxxxxxxx")
            .setBodyParameter("q", "food")
            .asJsonObject()
            .setCallback(new FutureCallback<JsonObject>() {
                @Override
                public void onCompleted(Exception e, JsonObject result) {
                    System.out.println("result = " + result);
                }
            });

I made this request with Ion library Android Ion library

I got this response:

{"statusCode":404,"message":"Resource not found"}

I followed Bing documentations carfully.

Web Search API Guide

Web Search API Reference

I made a call via "Postman" client on Desktop Chrome browser and I got good fully response.

What is missing with the Android request?

Update

I did the request with other AsyncHttp library called Android Asynchronous Http Client and it worked perfect!

I wonder what is wrong with Ion library..

Upvotes: 0

Views: 911

Answers (1)

Rob Truxal
Rob Truxal

Reputation: 6438

I may be missing something, but The above code doesn't seem to append a '?' to the end of ...com/bing/v5.0/search leaving you with ...com/bing/v5.0/searchq=food... which would deifnitely throw a 404 error.

What you would want is ...com/bing/v5.0/search?q=food...Perhaps the tool you used compensated for this.

Upvotes: 1

Related Questions