How to make OKHTTP post request without a request body?

前端 未结 3 1094
你的背包
你的背包 2021-02-06 22:24

Possible way to make OkHTTP post request without a request body in okhttp library ?

相关标签:
3条回答
  • 2021-02-06 22:46
        RequestBody reqbody = RequestBody.create(null, new byte[0]);  
        Request.Builder formBody = new Request.Builder().url(url).method("POST",reqbody).header("Content-Length", "0");
        clientOk.newCall(formBody.build()).enqueue(OkHttpCallBack());
    
    0 讨论(0)
    • "".toRequestBody()
    • "".toRequestBody("application/json".toMediaTypeOrNull())

    ...depends on which media type your endpoint expects.

    0 讨论(0)
  • 2021-02-06 23:02

    This worked for me:

    RequestBody body = RequestBody.create(null, new byte[]{});
    
    0 讨论(0)
提交回复
热议问题