大家好!
最近我在做一个能够在本地自动发布信息到网站上,实现网站数据自动更新的程序.我已经做了一个.但是始终没有调试成功.也没有什么错误信息.请教大家了! WebRequest request = WebRequest.Create("http://www.autosh.net/auto_secondhand/userpad/addmed.asp");
//Set the Method property of the request to POST
request.Method = "POST";
//Create POST data and convert it to a byte array
string postdata = "gq=供&t1=我的测试数据&picurl=&price=1222&[email protected]&t4=13501659342&t3=测试数据拉&d1=上海市&d2=8天";
byte[] byteArray = Encoding.UTF8.GetBytes(postdata);
//Set the ContentType property of the webrequest
request.ContentType = "application/x-www-form-urlencode";
//Set the ContentLength property of the WebRequest
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader sreader = new StreamReader(dataStream);
string str = sreader.ReadToEnd();
Console.WriteLine(str.ToString());
dataStream.Close();
response.Close();
最近我在做一个能够在本地自动发布信息到网站上,实现网站数据自动更新的程序.我已经做了一个.但是始终没有调试成功.也没有什么错误信息.请教大家了! WebRequest request = WebRequest.Create("http://www.autosh.net/auto_secondhand/userpad/addmed.asp");
//Set the Method property of the request to POST
request.Method = "POST";
//Create POST data and convert it to a byte array
string postdata = "gq=供&t1=我的测试数据&picurl=&price=1222&[email protected]&t4=13501659342&t3=测试数据拉&d1=上海市&d2=8天";
byte[] byteArray = Encoding.UTF8.GetBytes(postdata);
//Set the ContentType property of the webrequest
request.ContentType = "application/x-www-form-urlencode";
//Set the ContentLength property of the WebRequest
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader sreader = new StreamReader(dataStream);
string str = sreader.ReadToEnd();
Console.WriteLine(str.ToString());
dataStream.Close();
response.Close();
=====>
Encoding.Default.GetBytes(postdata);
确保所有数据提交根页面提交没任何区别。
string postdata = "gq=供&t1=我的测试数据&picurl=&price=1222&[email protected]&t4=13501659342&t3=测试数据拉&d1=上海市&d2=8天";
传过去没有用,数据库里面全是NULL