Commit 56bb50f8 authored by Administrator's avatar Administrator

add simple http invoker

parent 71f821e4
package com.virjar.ratel.api;
import android.util.Log;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import external.org.apache.commons.io.IOUtils;
public class SimpleHttpInvoker {
public static String get(String url) {
try {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("GET");
connection.connect();
int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
connection.disconnect();
return null;
}
try (InputStream inputStream = connection.getInputStream()) {
return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
} finally {
connection.disconnect();
}
} catch (Exception e) {
Log.e(RatelToolKit.TAG, "error for url:" + url, e);
return null;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment