求救post方法
我从网上找了一串代码但看不明白
代码如下:post方法,可以处理中文的url
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Web;
using MSXML2;
using System.Threading;
namespace Engine.Activity.FeeAgency
{
public class PostHttp
{
private PostHttp()
{
}
public static string Post_Http(string a_strUrl,string a_strPostData)
{
string strResult = " " ;
try
{
Encoding encoding = Encoding.GetEncoding( "GB2312 ");
string postData = a_strPostData;
string strUrl = a_strUrl;
byte[] data = encoding.GetBytes(postData);
// 准备请求...
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
myRequest.Method = "POST ";
myRequest.ContentType= "application/x-www-form-urlencoded ";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// 发送数据
newStream.Write(data,0,data.Length);
newStream.Close();
try
{
HttpWebResponse HttpWResp = (HttpWebResponse)myRequest.GetResponse();
Stream myStream = HttpWResp.GetResponseStream() ;
StreamReader sr = new StreamReader(myStream , Encoding.Default);
StringBuilder strBuilder = new StringBuilder();
while (-1 != sr.Peek())
{
strBuilder.Append(sr.ReadLine());
}
strResult = strBuilder.ToString();
}
catch(Exception exp)
{
strResult = "错误: " + exp.Message ;
}
}
catch(Exception exp)
{
strResult = "错误: " + &nbs