Skip to content

Instantly share code, notes, and snippets.

@addam01
Created July 9, 2015 15:47
Show Gist options
  • Save addam01/f5dbc57fca0cc315ea08 to your computer and use it in GitHub Desktop.
Save addam01/f5dbc57fca0cc315ea08 to your computer and use it in GitHub Desktop.
public class MVPJSONParse {
public static void Decode(){
}
/* Helper function. put it in the same page, or in a library */
protected static String downloadFile(String URL, String category) {
String data;
// to fill-in url content
StringBuilder builder = new StringBuilder();
try {
// local objects declarations
data = URLEncoder.encode("category", "UTF-8") + "=" + URLEncoder.encode(category, "UTF-8");
java.net.URL url = new URL(URL);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter
(conn.getOutputStream());
wr.write(data);
wr.flush();
BufferedReader reader = new BufferedReader
(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while ((line = reader.readLine()) != null) {
sb.append(line);
break;
}
return sb.toString();
} catch (Exception e) {
return "Exception: " + e.getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment