xUtils怎么post请求上传json数据
展开全部
//设置传输参数。
RequestParams params = new RequestParams("UTF-8");
try {
params.setBodyEntity(new StringEntity(gson.toJson(要转成json的对象),"UTF-8"));
params.setContentType("application/json");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
httpUtils.send(HttpMethod.POST, url,params,new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
return;
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
if(responseInfo.statusCode == 200){
Log.i("MyLog", "发送成功");
}
RequestParams params = new RequestParams("UTF-8");
try {
params.setBodyEntity(new StringEntity(gson.toJson(要转成json的对象),"UTF-8"));
params.setContentType("application/json");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
httpUtils.send(HttpMethod.POST, url,params,new RequestCallBack<String>() {
@Override
public void onFailure(HttpException arg0, String arg1) {
return;
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
if(responseInfo.statusCode == 200){
Log.i("MyLog", "发送成功");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询