private
string
PostWebRequest(
string
postUrl,
string
paramData, Encoding dataEncode)
{
string
ret =
string
.Empty;
try
{
byte
[] byteArray = dataEncode.GetBytes(paramData);
//转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(
new
Uri(postUrl));
webReq.Method =
"POST"
;
webReq.ContentType =
"application/x-www-form-urlencoded"
;
webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr =
new
StreamReader(response.GetResponseStream(), Encoding.Default);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
newStream.Close();
}
catch
(Exception ex)
{
Response.Write(ex.Message);
}
return
ret;
}
|
paramData格式为:a=1&b=2等;<br><br>-------------------------<br>下面为服务器端接收方法:
|
加载事件中:
//对应PostWebRequest方法
//Response.Write(string.Format("<?xml version=\"1.0\"?><params><title>{0}</title></params>",Request["a"]));
|
分类:
ASP.NET
本文转自左正博客园博客,原文链接:http://www.cnblogs.com/soundcode/archive/2013/03/18/2966278.html
,如需转载请自行联系原作者