mercredi 4 novembre 2015

Get HttpWebResponse although there is a 403 Error [duplicate]

This question already has an answer here:

I made a simple Get Request to a Website and wanted to get the Response. When i open this Website with my browser and Live HttpHeaders, i see that this website gives back "HTTP/1.1 403 Forbidden" but also returns Html Code and Headers. So i basically want to get the Response and somehow ignore the 403 Error.

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://ift.tt/1puGwko");
        req.Accept = "*/*";
        req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0";
        req.Host = "website.com";
        req.Referer = "http://ift.tt/1puGwko";
        req.Method = "GET";
        HttpWebResponse res = (HttpWebResponse)req.GetResponse();  ###Execution Stops here and gives 403 Error###
        Stream rStream = res.GetResponseStream();
        StreamReader reader = new StreamReader(rStream);
        String resp = reader.ReadToEnd();

Aucun commentaire:

Enregistrer un commentaire