Answer the question
In order to leave comments, you need to log in
How to pass parameters to doInBackground?
Sender handler = new Sender();
FormBody.Builder params= new FormBody.Builder();
params.add("param1", "val");
params.add("param2", "val");
result = handler.execute("https://domain.ru/",params).get();
public class Sender extends AsyncTask<String, FormBody.Builder, String> {
private static final OkHttpClient client = new OkHttpClient();
protected String doInBackground(String... arg) {
try {
RequestBody formBody = arg[1].build();
Request request = new Request.Builder()
.url(arg[0])
.post(formBody)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
} catch (Exception e) {
e.printStackTrace();
}
return "fail";
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question