request.getresponse出现404页面不存在错误

string url = "http://www.kyoto-np.co.jp/article.php?mid=P20100202000200&genre=N1&area=Z10";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
        using (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse())   //出错
        using (Stream st = response.GetResponseStream())
        using (StreamReader readStream = new StreamReader(st, Encoding.GetEncoding("EUC-JP")))
        {
            sss = readStream.ReadToEnd();
        }

 

改为

 

HttpWebResponse response = null;
        try
        {
            response = (HttpWebResponse)webRequest.GetResponse();

        }
        catch (WebException ex) {
            response = (HttpWebResponse)ex.Response;
        }

 


 

posted @ 2010-02-04 20:47  leic2000  阅读(439)  评论(0编辑  收藏  举报