webrequest post提交不上去
private void button5_Click(object sender, EventArgs e){
string a ="address=aaa&kind=住宅房&tel=12332112&userid=asmin&password&admin";
string dd = "";
PostPage("http://.../.../send_online/submita.asp",a,"gb2312",out dd);
}
public static string PostPage(string url, string postData, string encodeType, out string err)
{
//Stream outstream = null;
Stream instream = null;
StreamReader sr = null;
HttpWebResponse response = null;
HttpWebRequest request = null;
string content = null;
// Encoding encoding = Encoding.UTF8;
Encoding encoding = Encoding.GetEncoding(encodeType);
byte[] data = encoding.GetBytes(postData);
int iConnect = 0;
while (iConnect < 10) //提交10次,如果不成功则返回null
{
// 准备请求...
try
{
// 设置参数
request = (HttpWebRequest)WebRequest.Create(url);
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.UserAgent = "5DO8";
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream outstream = request.GetRequestStream();
outstream.Write(data, 0, data.Length);
outstream.Close();
//发送请求并获取相应回应数据
response = (HttpWebResponse)request.GetResponse();
//直到request.GetResponse()程序才开始向目标网页发送Post请求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回结果网页(html)代码
content = sr.ReadToEnd();
err = string.Empty;
return content;
}
catch (Exception ex)
{
err = ex.Message;
iConnect++;
if (iConnect >= 10)
return string.Empty;
else continue;
}
}
err = string.Empty;
if (iConnect >= 10)
return string.Empty;
else
return content;
}
页面为什么没有提交?!跪求原因! --------------------编程问答-------------------- 调试下,看暴什么异常? --------------------编程问答-------------------- 此法不行可使用XMLHTTPREQUEST对像。。
补充:.NET技术 , C#