private void post(String url) throws IOException {
RequestBody requestBody = new FormBody.Builder()
.add("account", "****")
.add("password", "****")
.build();
Request request = new Request.Builder()
.post(requestBody)
.url(url)
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36")
.build();
client.newCall(request).enqueue(new Callback() {
public void onFailure(@NotNull Call call, @NotNull IOException e) {
System.out.println("111");
}
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
System.out.println(response.body().string());
System.out.println("2222");
}
});
}
上面是post方法 和我调用了该方法后的执行结果,刚接触okhttp,找了挺多异步请求方法的例子,但按照他们的例子我的请求没有发出去(抓包发现没有发出请求,用同步能抓到)。还希望能有大佬指点指点。
牛年大吉!!