我是这样的代码块:
const string webServiceUrl = "https://test.xyxyx.com/App/Services/wService.svc?wsdl";
var postString = string.Format("Parameter1={0}&Parameter2={1}&Parameter3={2}&Parameter4={3}&Parameter5={4}&Parameter6={5}&Parameter7={6}&Parameter8={7}", "AA", "AB", "AC", "BA", "BB", BC, 5, 7);
const string contentType = "text/xml; charset=utf-8";
HttpWebRequest webRequest = WebRequest.Create(webServiceUrl) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.ContentType = contentType;
webRequest.Accept = "text/xml";
StreamWriter requestWriter = new StreamWriter(webRequest.GetRequestStream());
requestWriter.Write(postString);
requestWriter.Close();
StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
var responseData = responseReader.ReadToEnd();
responseReader.Close();
webRequest.GetResponse().Close();
我在这一行得到错误:
StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
远程服务器返回错误:(400)错误请求
为什么我会这样?我尝试了一些不同的方法,但结果是一样的。我该怎么办?
答案 0 :(得分:0)
我认为问题是您要发布到?wsdl
网址。
此外,您的内容不是xml。
通常,您可以检查返回页面的内容,它可能有更多详细信息。
最后查看.NET: Simplest way to send POST with data and read response。