Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.hisun.webservice.WebServiceCsvFile.main(WebServiceCsvFile.java:36)
代码如下:
public class WebServiceCsvFile {
public static void main(String[] args) throws Exception {
String urlString = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
String xmlFile = "111";// 要发送的soap格式文件
String soapActionString = "http://WebXml.com.cn/getWeatherbyCityName";//Soap 1.1中使用
URL url = new URL(urlString);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
File fileToSend = new File(xmlFile);
byte[] buf = new byte[(int) fileToSend.length()];// 用于存放文件数据的数组
new FileInputStream(xmlFile).read(buf);
// httpConn.setRequestProperty("Content-Length",
// String.valueOf(buf.length));//这句话可以不用写,即使是随便写
//根据我的测试,过去的请求头中的Content-Length长度也是正确的,也就是说它会自动进行计算
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestProperty("soapActionString",soapActionString);//Soap
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
out.write(buf);
out.close();
InputStreamReader is = new InputStreamReader(httpConn.getInputStream(),"utf-8");
BufferedReader in = new BufferedReader(is);
String inputLine;
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("result.xml")));// 将结果存放的位置
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
bw.write(inputLine);
bw.newLine();
}
bw.close();
in.close();
httpConn.disconnect();
}
}
看异常信息是webservice端处理请求时发生异常了,如果服务端是自已的就调试一下,如果不是就用soapui跑一下看看是否正常,然后再对比一下你post的数据看看是否一致,想法调整,我对java不熟,只能说个大概的思路是这样的。wsdl是不是有windows登录验证
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。