• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

httpclient调接口post出现无响应400

String uri=url+bundle.getString("postCookie.uri");    //生成httpclient对象   // CloseableHttpClient httpClient = HttpClientBuilder.create().build();   DefaultHttpClient httpClient = new DefaultHttpClient();    //创建post请求    HttpPost httpPost=new HttpPost(uri);    //使用json入参,入参是中文时不行。    JSONObject param=new JSONObject();    param.put("name","qinzhenxia");    param.put("age","28");    //设置请求头header    httpPost.setHeader("Content-Type","application/json;charset=gbk");    //传入参数    StringEntity entity=new StringEntity(param.toString(),"gbk");    httpPost.setEntity(entity);    //声明一个client对象,用来进行方法的执行,并设置cookies信息    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(this.store).build();    //执行请求并接收返回结果    HttpResponse httpResponse = httpClient.execute(httpPost);    String result=EntityUtils.toString(httpResponse.getEntity());    //判断返回code值    int statuscode=httpResponse.getStatusLine().getStatusCode();    if (statuscode==200){        System.out.println(result);    } else {        System.out.println("访问/postwithcookiesandjsontwo接口失败");    }    //获取返回结果并转换为jsonobject格式,然后获取某个具体的值通过断言判断    JSONObject resultjson=new JSONObject(result);    String msg =resultjson.getString("msg");    //判断msg等于success    Assert.assertEquals(msg,"success");    JSONObject p2pdata=resultjson.getJSONObject("p2pdata");    String address=p2pdata.getString("address");    Assert.assertEquals(address,"北三环");    System.out.println(address);}访问/postwithcookiesandjsontwo接口失败

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与2

//DefaultHttpClient httpClient = new DefaultHttpClient();
上面这句注释掉
HttpResponse httpResponse = httpClient.execute(httpPost);
httpClient改成httpclient,即
HttpResponse httpResponse = httpclient.execute(httpPost);

使用道具 举报

你用http 测试工具访问正常不正常再检查代码。也就是服务端接口正常了,才能说明你的客户端代码有问题。

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!