John Doe
John Doe

Reputation: 536

Bing image search API (cognitive) returns broken links?

I am using Azure cognitive service, more precisely the 'bing image search service'. I send requests to fetch images in relation to a specific keyword.

For this, I make HTTP REST requests to the right azure endpoint:

'https://api.cognitive.microsoft.com/bing/v7.0/images/search?q=MYKEYWORD'

It works well for a lot of requests and results.

However, in some images in the json response of the service, the field 'contentUrl' gives me a broken link to the website hosting the image (404 or 403 on some different wordpress sites for example).

Therefore, my program which tried to download the image thanks to the 'contentUrl' link crashes (or has to throw at least an exception).

I guess it is because the website changed (by removing the image they were hosting) and bing didn't update its database (or the crawler didn't have time to do so).

Hence I don't know what to do :'(

Any help / advice ?

Upvotes: 1

Views: 474

Answers (1)

George Chen
George Chen

Reputation: 14334

Yes, you are right, the contentUrl could be outdated cache removal.

By default, Bing returns cached content, if available. To prevent Bing from returning cached content, set the Pragma header to no-cache (for example, Pragma: no-cache).

You could check the Pragma header in this doc: Headers.

Upvotes: 2

Related Questions