第一种方式:
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);