代码如下
string url = "http://10.17.128.93:8006/FEDZ_GetLCData.asmx?op=GetLCInfo";
//设置post方式
string method = "POST";
StringBuilder sb = null;
sb = new StringBuilder();
sb.Append("StartDate=" + DateTime.Now);
sb.Append("EndDate=" + DateTime.Now.AddDays(1));
WebClient wc = new WebClient();
byte[] postData = Encoding.UTF8.GetBytes(sb.ToString().Trim());
wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
wc.Headers.Add("ContentLength", postData.Length.ToString());
byte[] getdata = wc.UploadData(url, method, postData);
wc.Dispose();
//处理返回数据(一般用json)
string srcString = Encoding.UTF8.GetString(getdata);
byte[] getdata = wc.UploadData(url, method, postData);这里出现500错误,原因是什么?
服务器内部错误,排查服务端代码。
如果你没有服务端代码,检查你的数据是否按要求格式上传。
POST /FEDZ_GetLCData.asmx HTTP/1.1 Host: 10.17.128.93 Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/GetLCInfo" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetLCInfo xmlns="http://tempuri.org/"> <StartDate>string</StartDate> <EndDate>string</EndDate> </GetLCInfo> </soap:Body> </soap:Envelope>
这是服务器代码我把application/x-www-form-urlencoded改成 text/xml还是不行。
@雍饱: 可以理解为,你调用的服务器端方法出现了异常,可能是你传参没按要求格式传,这个需要联调
@hahanonym: 怎么联调。。。
@雍饱: 客户端和服务端一起调试
@hahanonym: 谢谢了 问题已经解决了,用的版本不对导致的。