Search code examples
c#itunesitunes-search-api

iTunes Search API get 0 results at c# programm but 1 result at Chrome browser


I created a C# programm which searches movie details with the title of the movie. I create the link:

        string link = "https://itunes.apple.com/search?";

        link += "term=";

        string cTitle = Titel.Replace(" ", "+");
        link += cTitle;

        link += "&country=DE";
        link += "&media=movie";
        link += "&entity=movie";
        link += "&attribute=movieTerm";
        link += "&limit=1";

with the movie title "Bus 657" that would be the following link:

https://itunes.apple.com/search?term=Bus+657&country=DE&media=movie&entity=movie&attribute=movieTerm&limit=1

If I open that link I get a txt file with the result I need. But if I get that in c# with the following code:

WebClient client = new WebClient();
var json = client.DownloadString(link);
Thread.Sleep(3100);

I get 0 results. Can someone help me to fix that?

I have a lot movie titles which title are named by the original iTunes title of the store at germany.

Thx :)


Solution

  • Add the User Agent to the request header and try.

    WebClient client = new WebClient();
    client.Headers.Add("user-agent","Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
    var json = client.DownloadString(link);
    

    I received "resultCount":1