HttpWebRequest可以模拟xmlhttp的post么
某网站的post提交是用xmlhttp实现的,我用HttpWebRequest模拟这post时,收到的header跟在ie中提交的不一样,模拟失败了...= =
------解决方案--------------------public List <DvMsgResponse> Post()
{
List <DvMsgResponse> list = new List <DvMsgResponse> ();
if (!Dv_Config.API_Enable) return list;
string[] urls = Dv_Config.TargetUrls.Split( '| ');
byte[] bb = ToBytes();
foreach (string url in urls)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "post ";
req.ContentType = "text/xml ";
req.ContentLength = bb.Length;
req.KeepAlive = true;
Stream stream = req.GetRequestStream();
stream.Write(bb, 0, bb.Length);
stream.Close();
HttpWebResponse result = (HttpWebResponse)req.GetResponse();
Stream ReceiveStream = result.GetResponseStream();
Encoding enc = System.Text.Encoding.GetEncoding( "gb2312 ");
XmlDocument doc = new XmlDocument();
doc.Load(ReceiveStream);
list.Add(new DvMsgResponse(doc.DocumentElement));
}
return list;
}
类似这样的,我做过
往流里写内容就是了。。。
要找参考去我的blog,有一个针对动网,动易的三方接口,asp.net写的,看看吧
http://xiaoxiao.bfor.cn
------解决方案--------------------请求方式,设置
HttpWebRequest.Method = "post ";