62,072
社区成员
发帖
与我相关
我的任务
分享
public string PostModel(string strUrl, string strParm)
{
Encoding encode = System.Text.Encoding.Default;
byte[] arrB = encode.GetBytes(strParm);
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(strUrl);
myReq.Method = "POST";
//myReq.Referer = "http://www.zhaobiao.gov.cn/";
//myReq.ContentType = "multipart/form-data";
myReq.ContentType = "application/x-www-form-urlencoded";
myReq.ContentLength = arrB.Length;
Stream outStream = myReq.GetRequestStream();
outStream.Write(arrB, 0, arrB.Length);
outStream.Close();
WebResponse myResp = null;
try
{
//接收HTTP做出的响应
myResp = myReq.GetResponse();
}
catch (Exception e)
{
///
}
Stream ReceiveStream = myResp.GetResponseStream();
StreamReader readStream = new StreamReader(ReceiveStream, encode);
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
string str = null;
while (count > 0)
{
str += new String(read, 0, count);
count = readStream.Read(read, 0, 256);
}
readStream.Close();
myResp.Close();
return str;
}
}