重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍了post提交获得html页面的方法的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇post提交获得html页面的方法文章都会有所收获,下面我们一起来看看吧。
创新互联专注于延长网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供延长营销型网站建设,延长网站制作、延长网页设计、延长网站官网定制、成都小程序开发服务,打造延长网络公司原创品牌,更为您提供延长网站排名全网营销落地服务。
///
{
stringhttpString=string.Empty;
WebRequestrequest=WebRequest.Create(url);
request.Timeout=200000;
using(HttpWebResponseresponse=(HttpWebResponse)request.GetResponse())
{
if(response.StatusDescription.ToLower().Equals("ok"))
{
using(StreamReaderwriter=newStreamReader(response.GetResponseStream(),Encoding.GetEncoding("GB2312")))
{
httpString=writer.ReadToEnd();
}
}
}
returnhttpString;
}
///
{
stringhttpString=string.Empty;
WebRequestrequest=WebRequest.Create(url);
request.Timeout=200000;
using(HttpWebResponseresponse=(HttpWebResponse)request.GetResponse())
{
if(response.StatusDescription.ToLower().Equals("ok"))
{
using(StreamReaderwriter=newStreamReader(response.GetResponseStream(),Encoding.GetEncoding("UTF-8")))
{
httpString=writer.ReadToEnd();
}
}
}
returnhttpString;
}
///
{
varresult=string.Empty;
try{
varrequest=WebRequest.Create(url)asHttpWebRequest;
request.ContentType="text/json";
request.Method="post";
//request.CookieContainer=_cookie;
using(varstreamWriter=newStreamWriter(request.GetRequestStream()))
{
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
varresponse=(HttpWebResponse)request.GetResponse();
using(varreader=newStreamReader(response.GetResponseStream()))
{
result=reader.ReadToEnd();
}
}
}
catch(UriFormatExceptionuex)
{
//出错处理}
returnresult;
}
///
{
/***本函数只支持.net4.5以上的框架HttpClienthttpclient=newHttpClient();try{//打开页面httpclient.Credentials=CredentialCache.DefaultCredentials;//从指定的URI下载资源byte[]responseData=httpclient.DownloadData(strUrl);stringsrcString=RespEncode.GetString(responseData);
httpclient.Headers.Add("Content-Type","application/x-www-form-urlencoded");stringpostString=strParams;//将字符串转换成字节数组byte[]postData=Encoding.ASCII.GetBytes(postString);//上传数据,返回页面的字节数组responseData=httpclient.UploadData(strUrl,"POST",postData);srcString=ReqEncode.GetString(responseData);
returnsrcString;}catch(Exceptionex){//记录异常日志//释放资源httpclient.Dispose();returnstring.Empty;}*/return"";
}
///
{
WebClientclient=newWebClient();
System.Collections.Specialized.NameValueCollectionlist=newSystem.Collections.Specialized.NameValueCollection();
list.Add("opencheckindatatype","3");
list.Add("starttime","1492617600");
list.Add("endtime","1492790400");
//"useridlist":["james","paul"]list.Add("useridlist","['TuHuaXing']");
byte[]j=client.UploadValues(url,list);
//vardec=BitConverter.ToInt64(j,0);//stringjS=BitConverter.ToString(j);//jS=Convert.ToString(jS,10);returnSystem.Text.Encoding.Default.GetString(j);
//目标页面获取值request.form["id"]
/**WebRequestrequest7=WebRequest.Create(url);request7.Method="POST";
//post传参数byte[]bytes=Encoding.ASCII.GetBytes(postdata);request7.ContentType="application/x-www-form-urlencoded";request7.ContentLength=postdata.Length;request7.SStreamsendStream=request7.GetRequestStream();sendStream.Write(bytes,0,bytes.Length);sendStream.Close();
//得到返回值WebResponseresponse7=request7.GetResponse();stringOrderQuantity=newStreamReader(response7.GetResponseStream(),Encoding.GetEncoding("utf-8")).ReadToEnd();returnOrderQuantity;//转化成json对象处理//List>(OrderQuantity);**/}
关于“post提交获得html页面的方法”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“post提交获得html页面的方法”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注创新互联行业资讯频道。