调用第三方接口的几种请求方式


第一种方式:
String url4="https://www.showmebug.com/open_api/v1/interviews";
json=new JSONObject();
json.put("candidate_name", "张三");//传递的参数
MediaType mediaType = MediaType.parse("application/json;charset=utf-8");
RequestBody body = RequestBody.create(mediaType, String.valueOf(json));
Request request1 = new Request.Builder().url(url4).post(body)
   .addHeader("content-type", "application/json")
   .addHeader("Authorization","Bearer dCFoJ81lOpLhAhsEbtjjNNtcz8MqLr_dXWPqS6Lw8FM").build();
OkHttpClient client = new OkHttpClient();
Response response9 = client.newCall(request1).execute();
System.out.println(response9.body().string());

第二种方式:

String url2="https://www.showmebug.com/open_api/v1/interviews";
HttpPost httpPost2 = new HttpPost(url2);
httpPost2.addHeader("content-type", "application/json");
httpPost2.addHeader("Authorization", "Bearer a-TUxJs--67q8nty0rtISSg85lIZgcd81F_yR0MJ9-I");//设置token
// 发送请求
HttpClient httpclient3 = HttpClientBuilder.create().build();
HttpResponse response3 = httpclient3.execute(httpPost2);
// 处理返回结果
String resContl = EntityUtils.toString(response3.getEntity(), Consts.UTF_8);
System.out.println("==================================="+resContl);
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值