post请求soap服务,Java代码报错

弓_D_长 发布于 2016/09/09 15:10
阅读 457
收藏 0
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();  
    }  
}  

加载中
0
janl
janl
看异常信息是webservice端处理请求时发生异常了,如果服务端是自已的就调试一下,如果不是就用soapui跑一下看看是否正常,然后再对比一下你post的数据看看是否一致,想法调整,我对java不熟,只能说个大概的思路是这样的。
0
zy_3g
zy_3g
wsdl是不是有windows 登录验证
返回顶部
顶部