Last active
October 8, 2015 16:58
Revisions
-
janxious revised this gist
Jan 29, 2013 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,8 @@ public class JavaExample { public static void main(String[] args) throws Exception{ String document = "<html><body>This is a DocRaptor Example</body></html>"; String apikey = "YOUR_API_KEY_HERE"; String encoded_document = URLEncoder.encode(document, "UTF8"); String data = "doc[document_content]=" +encoded_document; data += "&doc[name]=java_sample.pdf"; data += "&doc[document_type]=pdf"; data += "&doc[test]=true"; -
janxious revised this gist
Aug 16, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,4 +36,4 @@ public static void main(String[] args) throws Exception{ responseStream.close(); outputStream.close(); } } -
janxious created this gist
Aug 15, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ import java.io.*; import java.net.*; public class JavaExample { public static void main(String[] args) throws Exception{ String document = "<html><body>This is a DocRaptor Example</body></html>"; String apikey = "YOUR_API_KEY_HERE"; String data = "doc[document_content]=" + document; data += "&doc[name]=java_sample.pdf"; data += "&doc[document_type]=pdf"; data += "&doc[test]=true"; byte[] encodedData = data.getBytes("UTF8"); String url = "https://docraptor.com/docs?user_credentials=" + apikey; String agent = "Mozilla/4.0"; String type = "application/x-www-form-urlencoded"; HttpURLConnection conn = (HttpURLConnection)new URL(url).openConnection(); conn.setDoOutput(true); // send as a POST conn.setRequestProperty("User-Agent", agent); conn.setRequestProperty("Content-Type", type); conn.setRequestProperty("Content-Length", Integer.toString(encodedData.length)); OutputStream os = conn.getOutputStream(); os.write(encodedData); os.flush(); InputStream responseStream = conn.getInputStream(); OutputStream outputStream = new FileOutputStream(new File("java_sample.pdf")); byte[] buffer = new byte[1024]; int len; while((len = responseStream.read(buffer)) > 0) { outputStream.write(buffer, 0, len); } responseStream.close(); outputStream.close(); } }