我有一个URL接口:
http://219.142.127.25/HBE/servlet/bookingcontroller?request=
后面接的是xml字符串我写的程序是:System.Xml.XmlDocument XMLDoc = new System.Xml.XmlDocument();
String InterfaceURL = "http://219.142.127.25/HBE/servlet/bookingcontroller";
XMLDoc.Load("EEEEEEEEEEEEEE.xml");//EEEEEEEEEEEEEE.xml存放正确格式的xml内容
Byte[] byte1 = System.Text.Encoding.GetEncoding("GB2312").GetBytes(XMLDoc.OuterXml);
WebRequest HttpWReq = WebRequest.Create(InterfaceURL);
HttpWReq.ContentType = "text/xml";
HttpWReq.ContentLength = XMLDoc.OuterXml.Length;
HttpWReq.Method = "POST";
System.IO.Stream StreamData = HttpWReq.GetRequestStream();
StreamData.Write(byte1,0,byte1.Length);
StreamData.Close();
WebResponse HttpWRes = HttpWReq.GetResponse();
System.IO.Stream receiveStream = HttpWRes.GetResponseStream();
XMLDoc = new System.Xml.XmlDocument();
XMLDoc.Load(receiveStream);
XMLDoc.Save("HBE_SAVE.xml");但是下载的内容是:(还有内容很奇怪啊??)
<?xml version="1.0" encoding="GB2312"?>
<OTResponse>
<TransactionName>Any</TransactionName>
<ErrorInfo>
<Code>-1</Code>
<Description>null</Description>
</ErrorInfo>
<Data>
</Data>
</OTResponse>但我在浏览器窗口直接输入http://219.142.127.25/HBE/servlet/bookingcontroller?request=...
却是有正确内容出来,而且使用
WebClient client = new WebClient();
client.DownloadFile(InterfaceURL,"111.xml");却是成功的,为什么????我错在那里,如何在WebRequest传递request的参数?????
http://219.142.127.25/HBE/servlet/bookingcontroller?request=
后面接的是xml字符串我写的程序是:System.Xml.XmlDocument XMLDoc = new System.Xml.XmlDocument();
String InterfaceURL = "http://219.142.127.25/HBE/servlet/bookingcontroller";
XMLDoc.Load("EEEEEEEEEEEEEE.xml");//EEEEEEEEEEEEEE.xml存放正确格式的xml内容
Byte[] byte1 = System.Text.Encoding.GetEncoding("GB2312").GetBytes(XMLDoc.OuterXml);
WebRequest HttpWReq = WebRequest.Create(InterfaceURL);
HttpWReq.ContentType = "text/xml";
HttpWReq.ContentLength = XMLDoc.OuterXml.Length;
HttpWReq.Method = "POST";
System.IO.Stream StreamData = HttpWReq.GetRequestStream();
StreamData.Write(byte1,0,byte1.Length);
StreamData.Close();
WebResponse HttpWRes = HttpWReq.GetResponse();
System.IO.Stream receiveStream = HttpWRes.GetResponseStream();
XMLDoc = new System.Xml.XmlDocument();
XMLDoc.Load(receiveStream);
XMLDoc.Save("HBE_SAVE.xml");但是下载的内容是:(还有内容很奇怪啊??)
<?xml version="1.0" encoding="GB2312"?>
<OTResponse>
<TransactionName>Any</TransactionName>
<ErrorInfo>
<Code>-1</Code>
<Description>null</Description>
</ErrorInfo>
<Data>
</Data>
</OTResponse>但我在浏览器窗口直接输入http://219.142.127.25/HBE/servlet/bookingcontroller?request=...
却是有正确内容出来,而且使用
WebClient client = new WebClient();
client.DownloadFile(InterfaceURL,"111.xml");却是成功的,为什么????我错在那里,如何在WebRequest传递request的参数?????
HttpRequest.InputStream 属性即可得到
-----------------------------------
net_lover(孟子E章) 你好,我最上面的例子不是使用http://219.142.127.25/HBE/servlet/bookingcontroller?request=x,而是使用
http://219.142.127.25/HBE/servlet/bookingcontroller的,帮我看看什么出错可以吗?
--------------------
按照你的意思,我已经修改成功了,我想请问一下。HttpWReq.ContentType = "text/xml";
HttpWReq.ContentType = "application/x-www-form-urlencoded";
这两个有什么差别?