读取网页图片(包含代理)

 WebRequest webRequest = WebRequest.Create("http://54.248.92.120/dscservice_api/api/person/632_12345.jpg");
        WebProxy p = null;  //代理类
        string proxyAddressAndPort = "guruproxy.bqc.corp.com";
        string proxyUserName = "账号";
        string proxyPwd = "密码";
        ICredentials cre; //身份验证信息类
        cre = new NetworkCredential(proxyUserName, proxyPwd); //得到用户名和密码
        p = new WebProxy(proxyAddressAndPort, true, null, cre); //将信息放于代理类中(代理服务器URl,是否跳过代理,,身份验证信息)
        WebRequest.DefaultWebProxy = p;
        HttpWebRequest request = webRequest as HttpWebRequest;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        string encoding = response.ContentEncoding;
        StreamReader reader = new StreamReader(response.GetResponseStream());
        var xx = reader.ReadToEnd();
        byte[] picbyte = Encoding.Default.GetBytes(xx);

 

posted @ 2013-11-08 15:26  帅的纯净水  阅读(224)  评论(0编辑  收藏  举报