Beispiel #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);
 }
Beispiel #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);
 }
Beispiel #3
0
 public Object getData(String url) throws IOException {
   return parseResponse(mOkHttpTool.get(url), Object.class);
 }
Beispiel #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;
 }