use of com.lidroid.xutils.http.RequestParams 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.http.RequestParams 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.http.RequestParams 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.http.RequestParams in project xUtils by wyouflf.
the class HttpRequest method setRequestParams.
public void setRequestParams(RequestParams param, RequestCallBackHandler callBackHandler) {
if (param != null) {
if (uriCharset == null) {
uriCharset = Charset.forName(param.getCharset());
}
List<RequestParams.HeaderItem> headerItems = param.getHeaders();
if (headerItems != null) {
for (RequestParams.HeaderItem headerItem : headerItems) {
if (headerItem.overwrite) {
this.setHeader(headerItem.header);
} else {
this.addHeader(headerItem.header);
}
}
}
this.addQueryStringParams(param.getQueryStringParams());
HttpEntity entity = param.getEntity();
if (entity != null) {
if (entity instanceof UploadEntity) {
((UploadEntity) entity).setCallBackHandler(callBackHandler);
}
this.setEntity(entity);
}
}
}
Aggregations