790
社区成员
发帖
与我相关
我的任务
分享
public static String doPost(String url,String execResult){
String result = "";
// 向服务器传送数据
HttpPost httpPost = new HttpPost(url);
// 先封装一个json对象
JSONObject param = new JSONObject();
List<NameValuePair> params = new ArrayList<NameValuePair>();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String time = df.format(new Date());
params.add(new BasicNameValuePair("time",time));
params.add(new BasicNameValuePair("phone",EnterActivity.edit_phone.getText().toString()));
params.add(new BasicNameValuePair("model","自助排障"));
params.add(new BasicNameValuePair("op_type", FlowPanelActivity.flow_name));
params.add(new BasicNameValuePair("op_detail ", execResult));
params.add(new BasicNameValuePair("op_result","成功"));
// 绑定到entity
try {
StringEntity entity = new StringEntity(params.toString());
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse response = new DefaultHttpClient().execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) {
result = EntityUtils.toString(response.getEntity());
}
} catch (Exception e) {
result = "提交失败";
e.printStackTrace();
}
return result;
}