如何使用application / x-www-form-urlencoded创建用于删除请求的httpclient

问题描述 投票:1回答:1

我正在创建此请求,但它作为get方法而不是像delete一样工作

 `public static void main(String[] args)  {     
    OkHttpClient client = new OkHttpClient();
    try {
    Request request = new Request.Builder()
      .url("https://qa.ecourierz.com/api/v1/bookings/ECZ159616")
      .delete()
      .addHeader("content-type", "application/x-www-form-urlencoded;charset=utf-8")
      .addHeader("x-api-token", "5dfb3ef7c11e1756916bb997-933f79708364c553a7c7352e7d2a6824cd48d8ed")
      .addHeader("cache-control", "no-cache")
      .build();
        Response response = client.newCall(request).execute();
        String body = response.body().string();
        System.out.println("body  "+body);
        System.out.println( "response---------------------    "+ response);
    } catch (IOException e) {
        System.out.println("hello");
        e.printStackTrace();
    }
java rest http url http-delete
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.