How to make OKHTTP post request without a request body?

梦想与她 提交于 2019-12-04 15:18:43

问题


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


回答1:


    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());



回答2:


This worked for me:

RequestBody body = RequestBody.create(null, new byte[]{});



回答3:


  • "".toRequestBody()
  • "".toRequestBody("application/json".toMediaTypeOrNull())

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



来源:https://stackoverflow.com/questions/35743516/how-to-make-okhttp-post-request-without-a-request-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!