Reading Response From URL using HTTP WEB REQUEST

后端 未结 2 539
無奈伤痛
無奈伤痛 2021-01-12 15:16

I have to read response from http://www.subway.com/storelocator/default.aspx?zip=04416&country=USA .I have used following code but does not get all the response. instead

2条回答
  •  情书的邮戳
    2021-01-12 15:35

    I don't know what you want to do with XmlTextReader since returned content is html not xml, however setting UserAgent is enough to get the page.

    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.subway.com/storelocator/default.aspx?zip=04416&country=USA");
    req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)";
    using (var resp = req.GetResponse())
    {
        var html = new StreamReader(resp.GetResponseStream()).ReadToEnd();
    }
    

提交回复
热议问题