new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
Looper.prepare();
String urlPath = Url.myURL4();
URL url;
try {
url = new URL(urlPath);
JSONObject ClientKey = new JSONObject();
ClientKey.put("c_hc_id", imei);
ClientKey.put("c_no", "000032");
ClientKey.put("c_sdt", startTime);
ClientKey.put("c_edt", endTime);
ClientKey.put("c_storeid", "101");
String content = String.valueOf(ClientKey);
Log.e("流水查询发送数据", content + "");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("ser-Agent", "Fiddler");
conn.setRequestProperty("Content-Type", "application/json");
OutputStream os = conn.getOutputStream();
Log.e("流水查询os", "0000000" + os);
os.write(content.getBytes());
os.close();
int code = conn.getResponseCode();
Log.e("流水查询code", code + "");
if (code == 200) {
Toast.makeText(BranchHistoricalActivity.this, "查询数据", Toast.LENGTH_SHORT).show();
InputStream is = conn.getInputStream();
String json = NetUtils.readString(is);
Log.e("流水查询获取返回的数据", json + "");
BranchHistoricalActivity.this.invalidateOptionsMenu();
//使用fastjson
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(json);
com.alibaba.fastjson.JSONArray jsonArray = jsonObject.getJSONArray("data");
shanghuXiaoShouBeans = jsonArray.parseArray(jsonArray.toString(), ShanghuXiaoShouBean.class);
Log.e("shanghuXiaoShouBeans", shanghuXiaoShouBeans + "");
} else {
Toast.makeText(getApplicationContext(), "数据提交失败", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "数据提交失败", Toast.LENGTH_SHORT).show();
}
Looper.loop();
}
}.start();