具有翻新和LiveData的cURL POST请求

时间:2019-07-04 13:09:56

标签: android curl post request retrofit2

我需要提出以下要求

cURL

  curl -X POST \
      http://reco.target.com/Q/V54XPVNVK1/ru/ \
      -H 'Accept: */*' \
      -H 'Connection: keep-alive' \
      -H 'Content-Type: application/json' \
      -H 'Host: reco.target.com' \

      -H 'User-Agent: PostmanRuntime/7.15.0' \
      -H 'accept-encoding: gzip, deflate' \
      -H 'cache-control: no-cache,no-cache' \
      -H 'content-length: 70' \
      -d '{
        "pID":"1222",
        "tID":"c3452b4f-345d-4345-b6be-4455948f3c77"
    }' 

这是我尝试过的:

 public interface ServerApi3 {

        @Headers({"Accept: */*", "Content-Type: application/json"})
        @POST("Q/V54XPVNVK1/ru")
        LiveData<ApiResponse<BlocksList>> geBlocksList(@Body BlocksBody body);

    }

    public class BlocksBody {

        @SerializedName("pID")
        String pID;

        @SerializedName("tID")
        String tID;

        public String getpID() {
            return pID;
        }

        public void setpID(String pID) {
            this.pID = pID;
        }

        public String gettID() {
            return tID;
        }

        public void settID(String tID) {
            this.tID = tID;
        }
    }

    private ServerApi3 createApi3() {

            Gson gson = new GsonBuilder()
                    .create();

            Retrofit.Builder retrofitBuilder = new Retrofit.Builder()
                    .addCallAdapterFactory(new LiveDataCallAdapterFactory())
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .client(getUnsafeOkHttpClient())
                    .baseUrl(BASE_URL3);

            return retrofitBuilder.build().create(ServerApi3.class);
        }

    public LiveData<ApiResponse<BlocksList>> getBlocks() {
            BlocksBody blocks = new BlocksBody();
            blocks.setpID("1222");
            blocks.settID("c3452b4f-345d-4345-b6be-4455948f3c77");
            return serverApi3.geBlocksList(blocks);

        }

调用serverApi3.geBlocksList(blocks),在终端中什么也没有。 没有拦截器消息,LiveData中没有响应(我的意思是回调)。

当我们通过Retrofit发出cURL POST请求时,也许有一种特殊的方法吗?我的意思是特殊注释。我不知道。

0 个答案:

没有答案