Is there any way to make a post request with OkHTTP that does not have a request body?
Create a MediaType variable named FORM: public static final MediaType FORM = MediaType. parse("multipart/form-data"); Create a RequestBody using the FORM variable and your unparsed params (String):
RequestBody requestBody = new MultipartBody. Builder() . setType(MultipartBody. FORM) .
OkHttp Query Parameters ExampleBuilder urlBuilder = HttpUrl. parse("https://httpbin.org/get).newBuilder(); urlBuilder. addQueryParameter("website", "www.journaldev.com"); urlBuilder. addQueryParameter("tutorials", "android"); String url = urlBuilder.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With