帮助,我不知道发生了什么,但我的OKHTTP应用程序没有做我想要的。 它启动和所有,没有错误等等,但根本不做run()方法。这是代码。
private final OkHttpClient client = new OkHttpClient();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_aktualnosci);
try {
run();
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() throws Exception {
Request request = new Request.Builder()
.url("http://publicobject.com/helloworld.txt")
.build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
Log.d("responseHeaders.name(i)", "responseHeaders.value(i)");
}
System.out.println(response.body().string());
}
我该如何解决?