public void getOkhttp() {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(str_log)
.build();
try {
Response response = client.newCall(request).execute();
str = response.body().string();
Toast.makeText(this, str + "", Toast.LENGTH_SHORT).show();
Log.e("TAG" , str + "") ;
} catch (IOException e) {
e.printStackTrace();
}
}
public void postOkhttp(){
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8") ;
OkHttpClient client = new OkHttpClient() ;
RequestBody body = RequestBody.create(JSON , str_json) ;
Request request = new Request.Builder()
.url(str_url + "方法名")
.post(body)
.build();
try {
Response response = client.newCall(request).execute() ;
Log.e("TAG" , response.body().string() + "") ;
} catch (IOException e) {
e.printStackTrace();
}
}