Get
public void getString(){
OkGo.<String>get("http://www.qubaobei.com/ios/cf/dish_list.php?stage_id=1&limit=20&page=1").execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
String body = response.body();
Toast.makeText(MainActivity.this, ""+body, Toast.LENGTH_SHORT).show();
}
@Override
public void onError(Response<String> response) {
super.onError(response);
}
});
}
Post
public void dopost(){
HashMap<String, String> map = new HashMap<>();
map.put("phone","18233790750");
map.put("passwd","345");
OkGo.<String>post("https://www.apiopen.top/createUser?key=00d91e8e0cca2b76f515926a36db68f5&").params(map).execute(new StringCallback() {
@Override
public void onSuccess(Response<String> response) {
Toast.makeText(MainActivity.this, ""+response.body(), Toast.LENGTH_SHORT).show();
}
});
}
下载
private void upload() {
OkGo.<String>post("http://172.21.79.88/hfs/").params("file",new File("/sdcard/来自天堂的魔鬼.mp3"),"ass.mp3")
.execute(new StringCallback(){
@Override
public void onSuccess(Response<String> response) {
Toast.makeText(MainActivity.this, ""+response.body(), Toast.LENGTH_SHORT).show();
}
@Override
public void uploadProgress(Progress progress) {
super.uploadProgress(progress);
bar.setProgress((int) (progress.fraction*100));
}
});
}
上传
private void upload() {
OkGo.<String>post("http://172.21.79.88/hfs/").params("file",new File("/sdcard/来自天堂的魔鬼.mp3"),"ass.mp3")
.execute(new StringCallback(){
@Override
public void onSuccess(Response<String> response) {
Toast.makeText(MainActivity.this, ""+response.body(), Toast.LENGTH_SHORT).show();
}
@Override
public void uploadProgress(Progress progress) {
super.uploadProgress(progress);
bar.setProgress((int) (progress.fraction*100));
}
});
}
请求图片
private void upload() {
OkGo.<String>post("http://172.21.79.88/hfs/").params("file",new File("/sdcard/来自天堂的魔鬼.mp3"),"ass.mp3")
.execute(new StringCallback(){
@Override
public void onSuccess(Response<String> response) {
Toast.makeText(MainActivity.this, ""+response.body(), Toast.LENGTH_SHORT).show();
}
@Override
public void uploadProgress(Progress progress) {
super.uploadProgress(progress);
bar.setProgress((int) (progress.fraction*100));
}
});
}