问题
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