if(this.proxyPort==null) this.ProxyPort="80"; WebProxy myProxy=new WebProxy(); myProxy = (WebProxy)request.Proxy; myProxy.Address = new Uri(this.ProxyAddress+":"+this.ProxyPort); myProxy.Credentials = new NetworkCredential(this.proxyAccount, this.proxyPassword, this.ProxyDomain); request.Proxy = myProxy; } try { //请求服务 WebResponse response = request.GetResponse(); //返回信息 Stream resStream = response.GetResponseStream(); StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default); string tempCode= sr.ReadToEnd(); resStream.Close(); sr.Close(); //如果输出文件路径为空,便将得到的内容赋给OutString属性 if(this.outFilePath==null) { this.outString=tempCode; } else { FileInfo fi = new FileInfo(this.outFilePath); //如果存在文件则先干掉 if(fi.Exists) fi.Delete(); StreamWriter sw = new StreamWriter(this.outFilePath,true,Encoding.Default); sw.Write(tempCode); sw.Flush(); sw.Close(); } } catch { this.noteMessage="出错了,请检查网络是否连通;"; } } #endregion } }
|