0
点赞
收藏
分享

微信扫一扫

记录java.io.IOException: Server returned HTTP response code: 500 for URL一次异常

窗外路过了谁 2022-04-17 阅读 27
java

项目场景:记录一次调用wsdl的bug

`一次调用其他厂家的webservice服务接口报错


问题描述

通过soapui调用接口正常返回出参,但是用代码调用则报错:
通讯模块2:java.io.IOException: Server returned HTTP response code: 500 for URL: http://xxx.xx.com/xxxWebService.asmx
`
先上调用代码,此代码在其他项目中都正常使用

public static String sendWebservice(String paramXml) {
		logger.info("接口入参明细:"+paramXml);
		URL wsUrl;
		String result = "";
		try {
			wsUrl = new URL(report_url);
			HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();
			conn.setDoInput(true);
			conn.setDoOutput(true);
			conn.setRequestMethod("POST");
			conn.setRequestProperty("User-Agent", "Mozilla/4.0(compatible;MSIE5.5;Windows NT; DigExt)");
			conn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
			conn.setConnectTimeout(2000);
			conn.setReadTimeout(2000);
			OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");
			out.write(paramXml);
			out.flush();
			// 请求体
			InputStream is = conn.getInputStream();   
			InputStreamReader isr = new InputStreamReader(is,"utf-8");
			BufferedReader in = new BufferedReader(isr);
			String inputLine;
			while ((inputLine = in.readLine()) != null)
			{
				System.out.println(inputLine);
			}
			in.close();
			/*BufferedReader in = new BufferedReader(new InputStreamReader(
					conn.getInputStream(),"utf-8"));
			String line;

			while ((line = in.readLine()) != null) {
				result += line;
			}
			logger.info("接口出参:"+result);
			out.close();
			conn.disconnect();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			logger.info("通讯模块1:" + e);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			logger.info("通讯模块2:" + e.toString());
		}
		return StringEscapeUtils.unescapeXml(result);
	}

在这里插入图片描述
soapui调用正常,比较了入参,检查是否有空格以及特殊字符,都没有,编码问题也改了好几遍都没有解决

原因分析:

>---

解决方案:

最后通过各种工具测试,发先apipost的请求头和soapui的请求头的
SOAPAction值有出入,apipost没有这个值,于是立刻补上,瞬间接口就可通了,然后就立刻在也把代码改了,也是可以了。

工具调用截图在这里插入图片描述

在的上面的代码加上这个配置就解决了。

conn.setRequestProperty("SOAPAction", "http://tempuri.org/HIPMessageServer");
举报

相关推荐

0 条评论