public void exec(HttpsCb cb) { try { if (!NetUtil.isConnected()) { ViewInject.toast("找不到网络了..."); return; } } catch (Exception e) { return; } if (mSslContext == null) { try { mSslContext = initCertificate(); } catch (Exception e) { e.printStackTrace(); ViewInject.toast("init ssl failed"); return; } } try { HttpsURLConnection conn = openConnection(); int code = conn.getResponseCode(); MLoger.debug("httpcode-->" + code); if (code == 200 || code == 201) { // 网络请求成功 String data = parseResponse(conn.getInputStream()); MLoger.debug("response data-->" + data); if (cb != null) cb.onResponse(data); } else { MLoger.debug("error httpcode-->" + code); } } catch (Exception e) { e.printStackTrace(); } }
protected String packageTextParamsForGet() { StringBuilder stringBuilder = new StringBuilder(); // 依次取出params里面的参数进行拼接 for (Map.Entry<String, String> entry : mParams.entrySet()) { stringBuilder.append(entry.getKey() + "=" + entry.getValue() + "&"); } String tmp = stringBuilder.toString(); if (tmp.endsWith("&")) { tmp = "?" + tmp; int len = tmp.length(); tmp = tmp.substring(0, len - 1); } MLoger.debug("packageTextParamsForGet:" + tmp); return tmp; }