httpPost一直 500,未将对象引用设置到对象的实例

来源:互联网 发布:alias软件下载 编辑:程序博客网 时间:2024/06/14 15:56

string xmlns="http://www.baitour.com/ ">&lt;ORDER_RETURNOUT_RS&gt;&lt;Error Code="11500000"&gt;11500000 Check UserInfo Error!未将对象引用设置到对象的实例。&lt;/Error&gt;&lt;/ORDER_RETURNOUT_RS&gt;</string>

一直请求不成功,但是浏览器测试请求是可以的。后来是因为httpPost.setEntity()的时候,setEntity(new StringEntity()),然后请求的协议也不是soap。
后来将换成setEntity(new UrlEncodeFormEntity())指定编码格式就可以了。

                String m ="<?xml version=\"1.0\" encoding=\"utf-8\"?><one><content>内容</content></one>";DefaultHttpClient httpClient = new DefaultHttpClient();httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000 * 10);// 连接时间httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,1000 * 20);// 数据传输时间NameValuePair param= new BasicNameValuePair("xmlDoc", m);List<NameValuePair> paramsList = new ArrayList<NameValuePair>();   //这里不是soap协议,需要参数以form表单形式提交paramsList.add(param);HttpPost httpPost = new HttpPost("http://ite.baitour.qunar.com/CoManage/BaitourService.asmx/RefundOrder");try {httpPost.setEntity(new UrlEncodedFormEntity(paramsList,"UTF-8"));  //这里原来一直new StringEntity(param,"UTF-8"),然后一直请求不成功HttpResponse response = httpClient.execute(httpPost);System.out.println("请求信息->"+m);System.out.println("结果-请求响应--->"+response);org.apache.http.HttpEntity resEntity = (org.apache.http.HttpEntity) response.getEntity();String result = EntityUtils.toString(resEntity,"UTF-8");System.out.println("结果-请求中的响应实体字符串result-->"+result);} catch (Exception e1) {e1.printStackTrace();}


原创粉丝点击