问题描述
怎么通过POST获取页面代码!急http://www2.baidu.com/inquire/rsquery.php搜索中国然后得到HTNL代码
解决方案
解决方案二:
我blog上的文章,是否满足要求privatestringgetWebresourceFile1(stringurl){WebClientmyWebClient=newWebClient();byte[]myDataBuffer=myWebClient.DownloadData(url);stringSourceCode=Encoding.Default.GetString(myDataBuffer);saveSourceCode(SourceCode);returnSourceCode;}方法2privatestringgetWebresourceFile2(stringurl){HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create(url);HttpWebResponseresponse=(HttpWebResponse)request.GetResponse();request.Method="GET";StreamreceiveStream=response.GetResponseStream();StreamReaderreadStream=newStreamReader(receiveStream,Encoding.Default);stringSourceCode=readStream.ReadToEnd();saveSourceCode(SourceCode);response.Close();readStream.Close();returnSourceCode;}方法3privatestringgetWebresourceFile3(stringurl){WebClientwc=newWebClient();wc.Credentials=CredentialCache.DefaultCredentials;Byte[]pageData=wc.DownloadData(url);stringSourceCode=Encoding.Default.GetString(pageData);saveSourceCode(SourceCode);wc.Dispose();returnSourceCode;}方法4privatestringgetWebresourceFile4(stringurl){WebClientwc=newWebClient();wc.Credentials=CredentialCache.DefaultCredentials;StreamresStream=wc.OpenRead(url);StreamReadersr=newStreamReader(resStream,System.Text.Encoding.Default);stringSourceCode=sr.ReadToEnd();saveSourceCode(SourceCode);resStream.Close();wc.Dispose();returnSourceCode;}方法5privatestringgetWebresourceFile5(stringurl){WebRequestrequest=WebRequest.Create(url);WebResponseresponse=request.GetResponse();StreamresStream=response.GetResponseStream();StreamReadersr=newStreamReader(resStream,System.Text.Encoding.Default);stringSourceCode=sr.ReadToEnd();saveSourceCode(SourceCode);resStream.Close();sr.Close();returnSourceCode;}
解决方案三:
没用啊