Search code examples
c#web-crawlerwebrequest

Web Request Response From Nike.com Forbidden


All I'm trying to do is create a program that gets a web response from Nike's upcoming shoe's page, however I keep running into an error saying this is forbidden. No other threads on this topic have been of use to me, is there anything I can do for this or am I just screwed? This is the code:

WebRequest request = WebRequest.Create("https://www.nike.com/launch/?s=upcoming");
WebResponse response = request.GetResponse();

and this is the error:

System.Net.WebException: 'The remote server returned an error: (403) Forbidden.'

Solution

  • Seems like a header issue, try this:

        WebClient client = new WebClient();
        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
        client.Headers.Add("Content-Type", "application / zip, application / octet - stream");
        client.Headers.Add("Referer", "http://whatevs");
        client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        String someStuff = client.DownloadString("https://www.hassanhabib.com");
        Console.WriteLine(someStuff);
        Console.Read();
    

    Removed the Accept-Encoding line, should be fine now.