Upload multiple files or a single

void uploadFile public () {
//192.168.1.104 native IP address
// due to a port conflict: http: //192.168.1.104: 8080 for the tomcat address
//http://192.168.1.104 as apache address
String url = " http://192.168.1.104:8080/FileUpload/FileUploadServlet ";
File = FileOne new new File (Environment.getExternalStorageDirectory ()," tiao.mp4 ");
File = FileTwo new new File (Environment.getExternalStorageDirectory ()," shumei.txt ");
IF (! fileOne.exists () || fileTWo.exists ()) {!
Toast.makeText (OkhttpUtilsActivity.this," file does not exist, modify the file path ", Toast.LENGTH_SHORT) the .Show ();
return ;
}
the Map <String, String> = paramsMap new new HashMap <> ();
// fill in the user name and password, and some server requires
paramsMap.put ( "username", "name");
paramsMap.put("password", "123");

OkHttpUtils.post()
.addFile("mFile", "server_afu.mp4", fileOne)
.addFile("mFile", "server_test.txt", fileTWo)
.url(url)
.params(paramsMap)
.build()
.execute(new MyStringCallback());
}
//获取图片
public void getPicture()
{
String url = "http://images.csdn.net/20150817/1.jpg";
String url2="http://pics.sc.chinaz.com/files/pic/pic9/201807/bpic7704.jpg";
OkHttpUtils
.get()
.url(url2)
.tag(this)
.build()
.connTimeOut(20000)
.readTimeOut(20000)
.writeTimeOut(20000)
.execute(new BitmapCallback() {
@Override
void the onError public (Call Call, E Exception, int ID) {

}

@Override
public void onResponse (Bitmap Bitmap, int ID) {
Log.e ( "the TAG", "onResponse: Complete");
imageView.setImageBitmap (Bitmap);
}
});
}
// okhttp-utils uploaded using a single file or a plurality of (parameters):
public void multiFileUpload ()
{
the HashMap <String, String> = new new Map the HashMap <> ();
map.put ( "the Action" , "AppVersion");
map.put ( "Version", "SS");
map.put ( "the Type", ". 1");

String URL = "request Interface address";
OkHttpUtils.post ()
.url (URL )
.params (Map)
.build ()
.execute (new new MyStringCallback ());
}
? Finally, the connection is broken and rewrite the http in onDestroy activities in

void the onPause public () {
super.onPause ();
// cancel your request, cancellation request according tag
OkHttpUtils.getInstance () cancelTag (this). ;

 

Guess you like

Origin www.cnblogs.com/hyhy904/p/11402889.html