我是网络服务的新手。
我必须将 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 错误请求缓存控制:私有内容类型:文本/xml;charset=utf-8 服务器:Microsoft-IIS/7.5 X-AspNet-Version:4.0.30319 X-Powered-By:ASP.NET 日期:星期四,2012 年 12 月 13 日 09:37:12 GMT 内容长度:0
我用谷歌搜索了错误并试图修复但没有解决方案出来..