post 发送和接收的问题
post后, 接收页面 接收到的数据为空。发送代码如下:
string postdata = @"<?xml version ='1.0'?><LTSC_command version='1.0'><command_name>provision</command_name><command_data_block><action_id>1</action_id><service_id>1008</service_id> <uid>100008888</uid><phone_number>85188888</phone_number><agent_name> OK820C-IACJ</agent_name><data_id>2688</data_id><area_code>1</area_code></command_data_block></LTSC_command>";
byte[] requestbytes = System.Text.Encoding.Default.GetBytes(postdata);
string url = "http://125.XX.XX.XXX/wapPost/Default2.aspx";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Timeout = 10000000; //设定超时值
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
req.ContentLength = requestbytes.Length;
Stream requeststream = req.GetRequestStream();
requeststream.Write(requestbytes, 0, requestbytes.Length);
requeststream.Close();
接收代码如下:
System.IO.StreamWriter swb = null;
string LogPath = Server.MapPath("log.txt");
swb = new System.IO.StreamWriter(@LogPath, true, System.Text.Encoding.Default);
swb.WriteLine("12345");
try
{
Stream resStream = Request.InputStream;
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
//Response.Write(sr.ReadToEnd());
// swb.Write(xmldoc.OuterXml);
swb.WriteLine(sr.ReadToEnd());
// swb.WriteLine("1234");
swb.close();
}
catch
{
}
--------------------编程问答-------------------- 不得哦!没人!!!!! --------------------编程问答-------------------- 不会 顶一下 --------------------编程问答--------------------
补充:.NET技术 , ASP.NET