// 1、构建请求队列 RequestQueue queue = SimpleNet.newRequestQueue(); // 2、创建请求 MultipartRequest multipartRequest = new MultipartRequest("你的url", new RequestListener<String>() { @Override public void onComplete(int stCode, String response, String errMsg) { // 该方法执行在UI线程 } }); // 3、添加各种参数 // 添加header multipartRequest.addHeader("header-name", "value"); // 通过MultipartEntity来设置参数 MultipartEntity multi = multipartRequest.getMultiPartEntity(); // 文本参数 multi.addStringPart("location", "模拟的地理位置"); multi.addStringPart("type", "0"); Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.thumb); // 直接从上传Bitmap multi.addBinaryPart("images", bitmapToBytes(bitmap)); // 上传文件 multi.addFilePart("imgfile", new File("storage/emulated/0/test.jpg")); // 4、将请求添加到队列中 queue.addRequest(multipartRequest); // 返回JSONObject的请求 // JsonRequest jsonRequest = new JsonRequest(HttpMethod.GET, "服务器地址", new RequestListener<JSONObject>() { // // @Override // public void onComplete(int stCode, JSONObject response, String errMsg) { // // } // // }) ;
最后,记得在Activity销毁时关闭消息队列。
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4