Skip to content

Instantly share code, notes, and snippets.

@shin1ogawa
Created January 14, 2010 16:43
Show Gist options
  • Save shin1ogawa/277305 to your computer and use it in GitHub Desktop.
Save shin1ogawa/277305 to your computer and use it in GitHub Desktop.
static final String BASEURL = "https://www.instapaper.com/api/";
static int addToInstaPaper(String username, String password, String url) throws IOException {
StringBuilder b = new StringBuilder();
b.append("username=").append(URLEncoder.encode(username, "utf-8"));
b.append("&password=").append(URLEncoder.encode(password, "utf-8"));
b.append("&url=").append(URLEncoder.encode(url, "utf-8"));
b.append("&auto-title=1");
byte[] payload = b.toString().getBytes("utf-8");
URL apiUrl = new URL(BASEURL + "add");
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStream os = connection.getOutputStream();
os.write(payload);
os.close();
return connection.getResponseCode();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment