.net后台以post方式调用http接口
string strResult = "";
try
{
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost:3256/NetCC_Agent.ashx?op=user_getuserlist&callback=ncc_getuser_callback&useraccount=czc@yuantel.com");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
try
{
HttpWebResponse HttpWResp = (HttpWebResponse)myRequest.GetResponse();
Stream myStream = HttpWResp.GetResponseStream();
StreamReader sr = new StreamReader(myStream, Encoding.UTF8);
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 = "错误:" + exp.Message;
}