use of com.lidroid.xutils.HttpUtils in project xUtils by wyouflf.
the class HttpFragment method testUpload.
/////////////////////////////////////// other ////////////////////////////////////////////////////////////////
//@OnClick(R.id.download_btn)
public void testUpload(View view) {
// 设置请求参数的编码
//RequestParams params = new RequestParams("GBK");
// 默认编码UTF-8
RequestParams params = new RequestParams();
//params.addQueryStringParameter("qmsg", "你好");
//params.addBodyParameter("msg", "测试");
// 添加文件
params.addBodyParameter("file", new File("/sdcard/test.zip"));
//params.addBodyParameter("testfile", new File("/sdcard/test2.zip")); // 继续添加文件
// 用于非multipart表单的单文件上传
//params.setBodyEntity(new FileUploadEntity(new File("/sdcard/test.zip"), "binary/octet-stream"));
// 用于非multipart表单的流上传
//params.setBodyEntity(new InputStreamUploadEntity(stream ,length));
HttpUtils http = new HttpUtils();
// 设置返回文本的编码, 默认编码UTF-8
//http.configResponseTextCharset("GBK");
// 自动管理 cookie
http.configCookieStore(preferencesCookieStore);
http.send(HttpRequest.HttpMethod.POST, "http://192.168.1.5:8080/UploadServlet", params, new RequestCallBack<String>() {
@Override
public void onStart() {
resultText.setText("conn...");
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
if (isUploading) {
resultText.setText("upload: " + current + "/" + total);
} else {
resultText.setText("reply: " + current + "/" + total);
}
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
resultText.setText("reply: " + responseInfo.result);
}
@Override
public void onFailure(HttpException error, String msg) {
resultText.setText(msg);
}
});
}
use of com.lidroid.xutils.HttpUtils in project xUtils by wyouflf.
the class HttpFragment method testGetSync.
// 同步请求 必须在异步块儿中执行
private String testGetSync() {
RequestParams params = new RequestParams();
params.addQueryStringParameter("wd", "lidroid");
HttpUtils http = new HttpUtils();
http.configCurrentHttpCacheExpiry(1000 * 10);
try {
ResponseStream responseStream = http.sendSync(HttpRequest.HttpMethod.GET, "http://www.baidu.com/s", params);
//Header[] headers = responseStream.getBaseResponse().getAllHeaders();
return responseStream.readString();
} catch (Exception e) {
LogUtils.e(e.getMessage(), e);
}
return null;
}
use of com.lidroid.xutils.HttpUtils in project xUtils by wyouflf.
the class HttpFragment method testPost.
//@OnClick(R.id.download_btn)
public void testPost(View view) {
RequestParams params = new RequestParams();
params.addQueryStringParameter("method", "mkdir");
params.addQueryStringParameter("access_token", "3.1042851f652496c9362b1cd77d4f849b.2592000.1377530363.3590808424-248414");
params.addBodyParameter("path", "/apps/测试应用/test文件夹");
HttpUtils http = new HttpUtils();
http.send(HttpRequest.HttpMethod.POST, "https://pcs.baidu.com/rest/2.0/pcs/file", params, new RequestCallBack<String>() {
@Override
public void onStart() {
resultText.setText("conn...");
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
resultText.setText(current + "/" + total);
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
resultText.setText("upload response:" + responseInfo.result);
}
@Override
public void onFailure(HttpException error, String msg) {
resultText.setText(msg);
}
});
}
use of com.lidroid.xutils.HttpUtils in project xUtils by wyouflf.
the class DownloadManager method addNewDownload.
public void addNewDownload(String url, String fileName, String target, boolean autoResume, boolean autoRename, final RequestCallBack<File> callback) throws DbException {
final DownloadInfo downloadInfo = new DownloadInfo();
downloadInfo.setDownloadUrl(url);
downloadInfo.setAutoRename(autoRename);
downloadInfo.setAutoResume(autoResume);
downloadInfo.setFileName(fileName);
downloadInfo.setFileSavePath(target);
HttpUtils http = new HttpUtils();
http.configRequestThreadPoolSize(maxDownloadThread);
HttpHandler<File> handler = http.download(url, target, autoResume, autoRename, new ManagerCallBack(downloadInfo, callback));
downloadInfo.setHandler(handler);
downloadInfo.setState(handler.getState());
downloadInfoList.add(downloadInfo);
db.saveBindingId(downloadInfo);
}
use of com.lidroid.xutils.HttpUtils in project xUtils by wyouflf.
the class DownloadManager method resumeDownload.
public void resumeDownload(DownloadInfo downloadInfo, final RequestCallBack<File> callback) throws DbException {
HttpUtils http = new HttpUtils();
http.configRequestThreadPoolSize(maxDownloadThread);
HttpHandler<File> handler = http.download(downloadInfo.getDownloadUrl(), downloadInfo.getFileSavePath(), downloadInfo.isAutoResume(), downloadInfo.isAutoRename(), new ManagerCallBack(downloadInfo, callback));
downloadInfo.setHandler(handler);
downloadInfo.setState(handler.getState());
db.saveOrUpdate(downloadInfo);
}
Aggregations