0

I am trying to get the Bing wallpaper data using the following request url: http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 I have the following code:

    private string getJsonData()
    {
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json");
            client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Dragon/43.3.3.185 Chrome/43.0.2357.81 Safari/537.36");

            using (var response = client.GetAsync("http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1").Result)
            {
                response.EnsureSuccessStatusCode();

                return response.Content.ReadAsStringAsync().Result;
            }
        }
    }

The problem is that I receive the copyrightlink equal to javascript:void(0), and as you can see, if I make the same request with the browser, I get a valid URL: http://www.bing.com/search?q=Brooklyn+Heights,+New+York&form=hpcapt&filters=HpDate:%2220150906_0700%22

I have tried quite a lot of things regarding the headers sent with the request, with no success, so I suppose the problem is coming from somewhere else. Any suggestions?

Note: the same issue is present when using xml as the requested format

Thanks!

Turcik
  • 1
  • 2
  • I've ran your code and it works perfectly. I get the copyright link as expected. – DanL Sep 07 '15 at 10:45
  • Ok, something is weird then. I've re-tested it using a console app, and nope, still no copyright link. – Turcik Sep 07 '15 at 15:37

2 Answers2

0

As javascript:void(0) means just undefined, I guess for the specific case there is just no copyright link (pointing to author web page, or something like that) at all. Only "© Andrew C. Mace/Getty Images"

Community
  • 1
  • 1
Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
  • Well, there is a copyright link, check this: http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1 or this: http://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1 – Turcik Sep 06 '15 at 18:48
  • I meant that the value of 'copyrightlink' property is 'javascript:void(0)' which means 'undefined' (or nothing, in other words - there is no real link like www.author-website.com - no link for this picture). I don't know why Bing team decided to use so strange value for empty 'copyrightlink' property... – Dmitry Pavlov Sep 07 '15 at 13:06
0

In the end, I've found the issue: it looks like I have to add the region in the request URL, like that: http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US. The copyrightlink is not javascript:void(0) in this case.

Turcik
  • 1
  • 2