//Response response = client.newCall(request).execute(); 上出现错误 return response.body().string();// 行。整个代码:`
OkHttpClient client = new OkHttpClient();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String run(String url) throws IOException {
Request request = new Request.Builder()
.url(url)
.build();
Response response = client.newCall(request).execute();
return response.body().string();
}
}`
我应该在哪里写我输入的url地址?在 OkHttp 文档中,它仅针对公共类显示。如果我在 MainActivity 中写这段代码,我应该在哪里写:
public static void main(String[] args) throws IOException{
OkHttpexample okHttpexample = new OkHttpexample();
String response =
okHttpexample.run("https://raw.github.com/square/okhttp/master/README.md");
System.out.println(response);}
如果你知道更多关于 OkHttp 的详细教程,那将会很有用