我在做什么: 我使用android http库来发出http请求
我在做什么: 我现在已经迁移到Oktttp,我正在使用下面的代码
在AsyncTask的doInBackground中我调用以下函数
public static String getRequestNoPayload(String urlString) throws Exception {
client.setConnectTimeout(20, TimeUnit.SECONDS); // connect timeout
client.setReadTimeout(20, TimeUnit.SECONDS); // socket timeout
Request request = new Request.Builder()
.url(urlString)
.addHeader("phonenumber",AppController.getPhoneNumber())
.addHeader("authtoken",AppController.getAuthCode())
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
网址的价值:
String urlString=Keys.login_api+"?phonenumber="+edtPhnoId.getText().toString().trim();
发生了什么:
答案 0 :(得分:0)
试试这个
RequestBody formBody = new FormEncodingBuilder()
.add("search", "Jurassic Park")
.build();
Request request = new Request.Builder()
.url("https://en.wikipedia.org/w/index.php")
.post(formBody)
.build();
Response response = client.newCall(request).execute();