How to make OKHTTP post request without a request body?
This worked for me:
RequestBody body = RequestBody.create(null, new byte[]{});
I'm using okhttp3
.
You can also do this for an empty request body:
val empty: RequestBody = EMPTY_REQUEST
For a POST
:
val request = Request.Builder().url(http).post(EMPTY_REQUEST).build()
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());