Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make OKHTTP post request without a request body?

Is there any way to make a post request with OkHTTP that does not have a request body?

like image 459
Justcurious Avatar asked Mar 02 '16 09:03

Justcurious


People also ask

How does OkHttp send raw data?

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):

How do you create a RequestBody in Java?

RequestBody requestBody = new MultipartBody. Builder() . setType(MultipartBody. FORM) .

How do I use Okhttpclient on Android?

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.


1 Answers

    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()); 
like image 151
Justcurious Avatar answered Oct 01 '22 01:10

Justcurious