问题描述
- jax-ws调用webService返回结果为json,使用拼装soap调用返回信息转义了
-
返回json:{"loginName":"admin1","msg":"return success","ret":"0"}
以下是调用方法:
public static String callWS(String SOAPUrl, String body) throws Exception {
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
String httpContent = body;
byte[] b = httpContent.getBytes("utf-8");
httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction", "");
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
out.write(b);
out.close();
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream(),"utf-8");
BufferedReader in = new BufferedReader(isr);
String result = "";
String inputLine;
while ((inputLine = in.readLine()) != null) {
result = result + inputLine;
}
in.close();
return result;
}返回信息如下:
<?xml version='1.0' encoding='UTF-8'?>
{"loginName":"admin1","msg":"return success","ret":"0"}
/ns2:singleLoginExResponse
/S:Body
/S:Envelope
返回的json信息中,引号被转义了,如何才能不装义,通过我的调用方法得到:
<?xml version='1.0' encoding='UTF-8'?>{"loginName":"admin1","msg":"return success","ret":"0"}
/ns2:singleLoginExResponse
/S:Body
/S:Envelope
这样的返回内容。(由于公司要求,必须采用这种调用方法callWS调webService,并且返回json字符串)
时间: 2024-12-29 00:15:39