Map<String, Object> map = new HashMap<>(8);
map.put("uid", entity.getUid());
String result = HttpURLConnectionUtil.get(IELTS_URL, map);
JSONObject jsonObject = JSONObject.fromObject(result);
Map<String,Object> map1 = (Map<String, Object>) jsonObject.get("data");
phone = map1.get("phone").toString();
public static String get(String url, Map<String, Object> param) {
StringBuilder builder = new StringBuilder();
try {
StringBuilder params = new StringBuilder();
for (Entry<String, Object> entry : param.entrySet()) {
if (entry.getValue() != null) {
params.append(entry.getKey());
params.append("=");
params.append(entry.getValue().toString());
params.append("&");
}
}
if (params.length() > 0) {
params.deleteCharAt(params.lastIndexOf("&"));
}
URL restServiceURL = new URL(url + (params.length() > 0 ? "?" + params.toString() : ""));
HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();
httpConnection.setRequestMethod("GET");
httpConnection.setRequestProperty("Accept", "application/json");
if (httpConnection.getResponseCode() != 200) {
throw new RuntimeException("HTTP GET Request Failed with Error code : "
+ httpConnection.getResponseCode());
}
InputStream inStrm = httpConnection.getInputStream();
byte[] b = new byte[1024];
int length = -1;
while ((length = inStrm.read(b)) != -1) {
builder.append(new String(b, 0, length));
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return builder.toString();
}