Error has appeared on //Response response = client.newCall(request).execute(); return response.body().string();// lines. The whole code: `
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();
}
}`
Where should I write url-adress which I enter? In OkHttp documentation it's shown only for public class. Where should I write this code if I wnat it in 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);}
If you know more detailed tutorials on OkHttp, it would be useful