[英]400 Bad request when pass xml to webservice
我是Web服务的新手。
我必须将xml传递给名为plog.asmx的aspx Web服务
这是我的代码
String xmldata = "<?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/\" >" +
"<![CD[<soap:Body>" +
"<SubmitJob xmlns=\"http://www.xdel.biz/XWS/\"> " +
"<APIKey>"+ API_KEY +"</APIKey>" +
"<Job>" +
"<Customer_Name>"+ Customer_Name +"</Customer_Name>" +
"<Address1>"+ Address1 +"</Address1>" +
"<Address2>"+ Address2 +"</Address2>" +
"<Postal_Code>"+ Postal_Code +"</Postal_Code>" +
"<Phone_Number>"+ Phone_Number +"</Phone_Number>" +
"<Mobile_Number>"+ Mobile_Number +"</Mobile_Number>" +
"<Order_Reference>"+ Order_Reference +"</Order_Reference>" +
"<Delivery_Instructions>"+ Delivery_Instructions +"</Delivery_Instructions>" +
"</Job>]]>" +
"</SubmitJob>" +
"</soap:Body>]]>" +
"</SOAP:Envelope>";
System.out.println(xmldata);
try{
//Create socket
String hostname = "www.xdel.biz";
int port = 80;
InetAddress addr = InetAddress.getByName(hostname);
Socket sock = new Socket(addr, port);
System.out.println(sock.toString());
//Send header
String path = "/xws/plog.asmx";
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(),"UTF-8"));
// You can use "UTF8" for compatibility with the Microsoft virtual machine.
wr.write("POST " + path + " HTTP/1.1\r\n");
wr.write("Host: www.xdel.biz\r\n");
wr.write("Content-Type: text/xml; charset=utf-8\r\n");
wr.write("Content-Length: " + xmldata.length() + "\r\n");
wr.write("SOAPAction: \"http://www.xdel.biz/XWS/SubmitJob\" \r\n");
wr.write("\r\n");
//Send data
wr.write(xmldata);
wr.flush();
System.out.println("1");
// Response
BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line;
while((line = rd.readLine()) != null){
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
当我运行代码时,出现这样的错误
HTTP / 1.1 400错误的请求缓存控制:私有Content-Type:text / xml; charset = utf-8服务器:Microsoft-IIS / 7.5 X-AspNet-版本:4.0.30319 X-Powered-通过:ASP.NET日期:2012年12月13日,星期四09:37:12 GMT内容长度:0
我搜索了该错误,并尝试修复,但没有解决方案。
可能是<![CD[<soap:Body></soap:Body>]]>
尝试在without ![CD[ ]] block
我已经有消耗Web服务的“错误请求”。 问题是,经过将近一天的寻找答案之后,我们发现这是消耗的XML的大小,消耗的SOAP消息的大小。 问题是,必须将提供要使用的Web服务的应用程序设置为接收大的XML数据,我们必须配置应用程序服务器以进行扩展以增加用于从客户端接收SOAP消息的缓冲区的大小。
那是我们的到期日。 我希望可以有所帮助。
我在HttpURLConnection
遇到了同样的问题。 添加以下两个属性解决了我的400 Bad Request问题:
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("soapAction", soapAction);
注意:当您尝试读取响应时,通常会出现此错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.