我有一个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的参数?????

解决方案 »

  1.   

    http://219.142.127.25/HBE/servlet/bookingcontroller?request=x是GET方式,你的程序是POST方式,看看你的程序是如何处理的
      

  2.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=ATV1GLXT-65FF-4M82-CT5U-B1J65D3ZN2OK
      

  3.   

    如果你提交的是xml文档,用
    HttpRequest.InputStream 属性即可得到
      

  4.   

    http://219.142.127.25/HBE/servlet/bookingcontroller?request=x是GET方式,你的程序是POST方式,看看你的程序是如何处理的
    -----------------------------------
    net_lover(孟子E章) 你好,我最上面的例子不是使用http://219.142.127.25/HBE/servlet/bookingcontroller?request=x,而是使用
    http://219.142.127.25/HBE/servlet/bookingcontroller的,帮我看看什么出错可以吗?
      

  5.   

    net_lover(孟子E章) 你好
    --------------------
    按照你的意思,我已经修改成功了,我想请问一下。HttpWReq.ContentType = "text/xml";
    HttpWReq.ContentType = "application/x-www-form-urlencoded";
    这两个有什么差别?