读取数:59595

代码如下:

Using SystemUsing SyUsing SyUsing SyUsing SyUsing SyUsing SyUsing SyUsing Sy。压缩;压缩。Using Sy。RegularExpressionsnamespace httpwebrequestdemo { class program { private static readonly string default user agent=' Mozilla(compatible;MSIE 6.0windows NT 5.2:SV1;NET CLR 1 . 1 . 4322;NET CLR 2 . 0 . 50727)’;private static bool checkvalidationresult(object sender、x509 certificate certificate、x509 chain chain、sslpolicyerrors esult)request=webre que(URL)as http web request;reque=H;Reque=' POSTreque=' application/x-www-form-urlencoded 'Reque=DefaultUserAgent//POST数据if(!(parameters==null | |==0){ string builder buffer=new string builder();int I=0;foreach(string key in){ if(i0){ bu(' { 0 }={ 1 } 'key,parameters[key]);} else {bu ('{0}={1} '键,参数[键]);} I;} byte[]data=c();Using (streamstream=reque ()) {(数据,0,da);} } return reque()as http webresponse;} staticvoidmain(string[]args){ string URL='Encodingencoding=encoding . getencoding(' utf-8 ');Idictionarystring,string parameters=new dictionary string,string();(' authuser '' * * * * ');(' authpass '' * * * * ');(' orgkey '' * * * * ');(' orgname '' * * * * ');http webresponseresponse=program . createposthttpresponse(URL、parameters、encoding);//打印返回值Stream Stream=re();//获取响应的字符串流stream reader Sr=new stream reader(stream);//创建流读取流string html=();//从头到尾字符串html Con(html);} }}HttpWebRequest默认情况下使用代理连接,因此导入结果很慢。

解决办法是,配置:

reque = null;

不使用代理,即可。

相关推荐