strPostData += String.Format("&txt_Number={0}&txt_YZM={1}&__VIEWSTATE={2}&__EVENTVALIDATION={3}"
, this.UserName
, this.ExPwd
, this.__VIEWSTATE
, this.__EVENTVALIDATION
);
strPostData = strPostData + "&IBt_ecall.x=8&IBt_ecall.y=12";
System.Threading.Thread.Sleep(5000); strHTML = GetHTML(strPostData,strPostData,Encoding.Default);
}public string GetHTML(string URL)
{
return GetHTML(URL, "", null);
}
public string GetHTML(string URL, System.Text.Encoding encoding)
{
return GetHTML(URL, "", encoding);
}
/// <summary>
// 获取指定地址的html
public string GetHTML(string URL, string PostData, System.Text.Encoding encoding)
{
string _Html = ""; try
{
Variant.Err = "";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(URL));
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
request.CookieContainer = this.ReqCookies; if (encoding == null)
encoding = Encoding.Default; //设置cookie
if (Variant.CurrentUser != null)
{
CookieCollection tmpCookies = Variant.CurrentUser.Cookies; System.Uri uri = new Uri(URL); foreach (System.Net.Cookie cookie in tmpCookies)
{
cookie.Domain = uri.Host;
if (cookie.Value.Length != 0)
{
request.CookieContainer.Add(cookie);
}
else
{
//Console.WriteLine(cookie.ToString());
}
} } //提交的数据
if (PostData != null && PostData.Length > 0)
{
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST"; byte[] b = encoding.GetBytes(PostData);
request.ContentLength = b.Length;
using (System.IO.Stream sw = request.GetRequestStream())
{
try
{ sw.Write(b, 0, b.Length);
}
catch
{ _Html = "";
return _Html;
}
finally
{
//if (sw != null) { sw.Close(); }
}
} }
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
try
{
response = (HttpWebResponse)request.GetResponse();
this.Cookies.Add(response.Cookies);
sr = new System.IO.StreamReader(response.GetResponseStream(), encoding);
_Html = sr.ReadToEnd();
}
catch (WebException webex)
{
if (webex.Status == WebExceptionStatus.KeepAliveFailure)
{
_Html = "";
Variant.Err = "KeepAliveFailure";
return _Html;
}
else
{
_Html = "";
Variant.Err = webex.Message;
return _Html;
}
}
catch (System.Exception ex)
{
_Html = "";
Variant.Err = ex.Message;
return _Html;
}
finally
{
if (sr != null) { sr.Close(); }
if (response != null) { response.Close(); }
response = null;
request = null;
}
return _Html;
}
catch
{
return "";
}
}
在这里,我是要将想将参数提交到目的网站.请帮我看看哪里有问题?应该如何解决呀
, this.UserName
, this.ExPwd
, this.__VIEWSTATE
, this.__EVENTVALIDATION
);
strPostData = strPostData + "&IBt_ecall.x=8&IBt_ecall.y=12";
System.Threading.Thread.Sleep(5000); strHTML = GetHTML(strPostData,strPostData,Encoding.Default);
}public string GetHTML(string URL)
{
return GetHTML(URL, "", null);
}
public string GetHTML(string URL, System.Text.Encoding encoding)
{
return GetHTML(URL, "", encoding);
}
/// <summary>
// 获取指定地址的html
public string GetHTML(string URL, string PostData, System.Text.Encoding encoding)
{
string _Html = ""; try
{
Variant.Err = "";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(URL));
request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
request.CookieContainer = this.ReqCookies; if (encoding == null)
encoding = Encoding.Default; //设置cookie
if (Variant.CurrentUser != null)
{
CookieCollection tmpCookies = Variant.CurrentUser.Cookies; System.Uri uri = new Uri(URL); foreach (System.Net.Cookie cookie in tmpCookies)
{
cookie.Domain = uri.Host;
if (cookie.Value.Length != 0)
{
request.CookieContainer.Add(cookie);
}
else
{
//Console.WriteLine(cookie.ToString());
}
} } //提交的数据
if (PostData != null && PostData.Length > 0)
{
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST"; byte[] b = encoding.GetBytes(PostData);
request.ContentLength = b.Length;
using (System.IO.Stream sw = request.GetRequestStream())
{
try
{ sw.Write(b, 0, b.Length);
}
catch
{ _Html = "";
return _Html;
}
finally
{
//if (sw != null) { sw.Close(); }
}
} }
HttpWebResponse response = null;
System.IO.StreamReader sr = null;
try
{
response = (HttpWebResponse)request.GetResponse();
this.Cookies.Add(response.Cookies);
sr = new System.IO.StreamReader(response.GetResponseStream(), encoding);
_Html = sr.ReadToEnd();
}
catch (WebException webex)
{
if (webex.Status == WebExceptionStatus.KeepAliveFailure)
{
_Html = "";
Variant.Err = "KeepAliveFailure";
return _Html;
}
else
{
_Html = "";
Variant.Err = webex.Message;
return _Html;
}
}
catch (System.Exception ex)
{
_Html = "";
Variant.Err = ex.Message;
return _Html;
}
finally
{
if (sr != null) { sr.Close(); }
if (response != null) { response.Close(); }
response = null;
request = null;
}
return _Html;
}
catch
{
return "";
}
}
在这里,我是要将想将参数提交到目的网站.请帮我看看哪里有问题?应该如何解决呀
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货