100分 求解 ... HttpWebRequest 无法发送数据, 传回的值只是Re :
如果在URL直接加参数又可以正常返回值. 何解 ? 谢谢各位!
发送代码
string strParm = "A=我晕 ";
HttpWebResponse result = null;
Encoding encoding = Encoding.GetEncoding( "GB2312 ");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create( "http://localhost/Default.aspx ");
req.ContentType = "application/x-www-form-urlencoded ";
req.Method = "POST ";
byte[] SomeBytes = encoding.GetBytes(strParm);
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
result = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(result.GetResponseStream(), encoding);
Response.Write(sr.ReadToEnd());
sr.Close();
result.Close();
接收代码:
<%@ Page Language= "C# " ValidateRequest= "false " %>
<script runat= "server ">
public void Page_Load(object sender, System.EventArgs e)
{
Response.Write( "Re : " + Request.QueryString[ "username "] ) ;
}
</script>
------解决方案--------------------application/x-www-form-urlencoded 这种方式的数据是不能用QueryString来收的
Request.Form[ "A "]
------解决方案--------------------在URL直接加参数又可以
就用get方法,直接传url
HttpWebRequest req = (HttpWebRequest)WebRequest.Create( "http://localhost/Default.aspx?username=testname ");
req.CookieContainer = new CookieContainer();
result = (HttpWebResponse)req.GetResponse();
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
最新版本:20070212
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html