public static String postData1(String urlAddress, String encodedType,Map params) {
try {
URL url = new URL(urlAddress);
URLConnection conn = url.openConnection();
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false); // Post请求不用设置缓存
conn.getOutputStream();
// 获取返回数据
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String line = null;
StringBuffer sb = new StringBuffer();
while ((line = in.readLine()) != null) {
sb.append(line);
}
in.close(); // 关闭流
return sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
使用上述的代码访问webservice,如果不加conn.getOutputStream(),返回soap协议正确,如果加上这一句,报错500,服务器那边显示错误:不能创建一个安全的xmlInputFactory:java.lang.RuntimeException: Cannot create a secure XMLInputFactory。
这是什么原因呢?在线等待,大家帮帮忙......