Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String performPostCall(String requestURL,String filename, String base64) {
- URL url;
- String response = "";
- try {
- url = new URL(requestURL);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- // conn.setReadTimeout(context.getResources().getInteger(
- // R.integer.maximum_timeout_to_server));
- // conn.setConnectTimeout(context.getResources().getInteger(
- // R.integer.maximum_timeout_to_server));
- conn.setRequestMethod("POST");
- conn.setDoInput(true);
- conn.setDoOutput(true);
- conn.setRequestProperty("Content-Type", "application/json");
- Log.e(TAG, "11 - url : " + requestURL);
- /*
- * JSON
- */
- JSONObject root = new JSONObject();
- //
- root.put("filename", filename);
- root.put("base64", base64);
- Log.e(TAG, "12 - root : " + root.toString());
- String str = root.toString();
- byte[] outputBytes = str.getBytes("UTF-8");
- OutputStream os = conn.getOutputStream();
- os.write(outputBytes);
- int responseCode = conn.getResponseCode();
- Log.e(TAG, "13 - responseCode : " + responseCode);
- if (responseCode == HttpsURLConnection.HTTP_OK) {
- Log.e(TAG, "14 - HTTP_OK");
- String line;
- BufferedReader br = new BufferedReader(new InputStreamReader(
- conn.getInputStream()));
- while ((line = br.readLine()) != null) {
- response += line;
- }
- } else {
- Log.e(TAG, "14 - False - HTTP_OK");
- response = "";
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return response;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement