我使用下面的方式请求
public static String postData1(String urlAddress, String encodedType, Map params) {
try {
URL url = new URL(urlAddress);
URLConnection conn = url.openConnection(); // 打开联接
// 使用POST请求,是否向connection输出/输入,因为这个是post请求,参数要放在http正文内,因此需要设为true
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false); // Post请求不用设置缓存
// 发送域信息
OutputStreamWriter out = new
OutputStreamWriter(conn.getOutputStream(), "utf-8");
StringBuffer stringBuffer = new StringBuffer();
if (params != null && !params.isEmpty()) {
for (Map.Entry<String, String> entry : params.entrySet()) {
try {
stringBuffer
.append(entry.getKey())
.append("=")
.append(URLEncoder.encode(entry.getValue(),
encodedType)).append("&");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// 删掉最后一个 & 字符
out.write(stringBuffer.toString());
out.flush();
out.close(); // 关闭流
// 获取返回数据
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 "";
}
不带参数的时候,正确,访问加上参数,出现Server returned HTTP response code: 500 for URL,服务端报错:
Interceptor for {http://service.cxf.myfund.com/}ServiceImplService has thrown exception, unwinding now
java.lang.RuntimeException: Cannot create a secure XMLInputFactory
at org.apache.cxf.staxutils.StaxUtils.createXMLInputFactory(StaxUtils.java:311)
at org.apache.cxf.staxutils.StaxUtils.getXMLInputFactory(StaxUtils.java:261)
at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(StaxUtils.java:1412)
.......
网上查找,缺少jar包,可是我的都有呢!
这是什么问题呢?急求急求。。。。。。