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。
這是什麼原因呢?在線等待,大家幫幫忙......
http://blog.csdn.net/fengcheqidong/article/details/40423517
終於解決了!!!