Created
November 24, 2014 12:21
-
-
Save devrath/d96051592d017095245a to your computer and use it in GitHub Desktop.
Passing data to http GET request as header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void getRequest(String urlString) { | |
URL url; | |
InputStream response = null; | |
try { | |
url = new URL(urlString); | |
HttpURLConnection connection; | |
connection = (HttpURLConnection) url.openConnection(); | |
connection.setRequestMethod("GET"); | |
connection.setRequestProperty("phonenumber", "1234"); | |
connection.setRequestProperty("authtoken", "1234"); | |
response = connection.getInputStream(); | |
String stringRep=IOUtils.toString(response); | |
JSONArray responseArray = new JSONArray(stringRep); | |
//jsonobject = new JSONObject(stringRep); | |
listData=new ArrayList<HashMap<String,String>>(); | |
for(int i=0; i<responseArray.length();i++){ | |
mapData=new HashMap<String, String>(); | |
JSONObject temp_obj = responseArray.getJSONObject(i); | |
mapData.put("id", temp_obj.getInt("id")+""); | |
mapData.put("name", temp_obj.getString("name")); | |
mapData.put("description", temp_obj.getString("description")); | |
mapData.put("isactive", temp_obj.getBoolean("isactive")+""); | |
listData.add(mapData); | |
} | |
System.out.println(listData); | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment