Exemplo n.º 1
0
 public DemoAPI() {
   mOkHttpTool = new OkHttpTool();
   gson = new Gson();
   Map<String, String> defaultHeaders = new HashMap<String, String>();
   defaultHeaders.put("Content-Type", "application/json");
   mOkHttpTool.setDefaultHeaders(defaultHeaders);
 }
Exemplo n.º 2
0
 public Object postData(String url, String userId, String data) throws IOException {
   List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
   params.add(new BasicNameValuePair("userid", userId));
   params.add(new BasicNameValuePair("data", data));
   return parseResponse(mOkHttpTool.post(url, new UrlEncodedFormEntity(params)), Object.class);
 }
Exemplo n.º 3
0
 public Object getData(String url) throws IOException {
   return parseResponse(mOkHttpTool.get(url), Object.class);
 }
Exemplo n.º 4
0
 private <T> T parseResponse(HttpURLConnection connection, Type type) throws IOException {
   BufferedReader bufferedReader = mOkHttpTool.getBufferedInputReader(connection);
   T response = gson.fromJson(bufferedReader, type);
   connection.disconnect();
   return response;
 }