public static String post(String ss) throws Exception {
String code = "";
//拼装参数
Map postmap = new HashMap();
postmap.put("_imei",ss);
//KeyService keyService = new KeyServiceImpl();
//List<DataShopJson> list = keyService.getProvincesByImei(key);
JSONObject json = new JSONObject();
json.accumulate("_authority_json", list);
String str = json.toString();
//去掉list的头部 -- no use
//str = str.replace("\"list\":", "");
postmap.put("_authority_json",str);
logOper("单条激活");
URL url=new URL(posturl);
URLConnection rulConnection = url.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection;
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.connect();
OutputStream outStrm = httpUrlConnection.getOutputStream();
OutputStreamWriter objOutputStrm = new OutputStreamWriter(outStrm, "UTF-8");
StringBuffer params = new StringBuffer();
Iterator it = postmap.entrySet().iterator();
while(it.hasNext()){
Entry element = (Entry)it.next();
params.append(element.getKey());
params.append("=");
params.append(element.getValue());
params.append("&");
}
if(params.length() > 0){
params.deleteCharAt(params.length()-1);
}
objOutputStrm.write(params.toString());
objOutputStrm.flush();
objOutputStrm.close();
InputStream inStrm = httpUrlConnection.getInputStream();
//获取接口的返回值
StringBuffer info = new StringBuffer();
BufferedInputStream buf = new BufferedInputStream(inStrm);
byte[] buffer = new byte[1024];
int iRead;
while ((iRead = buf.read(buffer)) != -1) {
info.append(new String(buffer, 0, iRead, "UTF-8"));
}
code = JSONObject.fromObject(info.toString()).get("_code").toString();
DataShopPostUtil.logOper("处理结果code===="+code);
inStrm.close();
return code.trim();
}