Last active
July 22, 2019 00:22
-
-
Save DJCordhose/4674139 to your computer and use it in GitHub Desktop.
Ultradox POST parameters
This file contains 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 characters
package com.floreysoft.sandbox; | |
import static com.google.appengine.api.urlfetch.FetchOptions.Builder.withDefaults; | |
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import com.google.appengine.api.urlfetch.HTTPHeader; | |
import com.google.appengine.api.urlfetch.HTTPMethod; | |
import com.google.appengine.api.urlfetch.HTTPRequest; | |
import com.google.appengine.api.urlfetch.HTTPResponse; | |
import com.google.appengine.api.urlfetch.URLFetchService; | |
import com.google.appengine.api.urlfetch.URLFetchServiceFactory; | |
import com.google.gson.Gson; | |
@SuppressWarnings("serial") | |
public class App_Engine_SandboxServlet extends HttpServlet { | |
public void doGet(HttpServletRequest req, HttpServletResponse resp) | |
throws IOException { | |
// this example requires GSON: http://code.google.com/p/google-gson/ | |
URLFetchService urlFetchService = URLFetchServiceFactory | |
.getURLFetchService(); | |
URL url = new URL( | |
"http://www.ultradox.com/ultradoc/execute?id=JaFxzA9G0ac4Npx83lvY78M9kO5lNO&action=DOWNLOAD"); | |
HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST, | |
withDefaults().setDeadline(30.0)); | |
Gson gson = new Gson(); | |
Payload payload = new Payload("Sales Representative", "2013-01-31", | |
true); | |
String json = gson.toJson(payload); | |
request.setPayload(json.getBytes()); | |
request.setHeader(new HTTPHeader("Content-Type", "application/json")); | |
HTTPResponse response = urlFetchService.fetch(request); | |
int code = response.getResponseCode(); | |
if (code == HttpURLConnection.HTTP_OK ) { | |
byte[] content = response.getContent(); | |
resp.getOutputStream().write(content); | |
} | |
} | |
public static class Payload { | |
public String position; | |
public String dateOfInterview; | |
public boolean refused; | |
public Payload() { | |
} | |
public Payload(String position, String dateOfInterview, boolean refused) { | |
this.position = position; | |
this.dateOfInterview = dateOfInterview; | |
this.refused = refused; | |
} | |
} | |
} |
This file contains 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 characters
function postParameters() { | |
var payload = { | |
position: "Sales Representative", | |
dateOfInterview: "2013-01-31", | |
refused: true | |
}; | |
var options = { | |
contentType: "application/json", | |
method : "post", | |
payload : Utilities.jsonStringify(payload) | |
}; | |
var response = UrlFetchApp.fetch('http://www.ultradox.com/ultradoc/execute?id=JaFxzA9G0ac4Npx83lvY78M9kO5lNO&action=DOWNLOAD',options) | |
var blob = response.getBlob(); | |
var code = response.getResponseCode(); | |
Logger.log(code === 200 ? "Success" : "Error Code: " + code); | |
// sending out email just for demo purposes | |
// in real applications send out personalized emails using Ultradox instead | |
GmailApp.sendEmail("[your email goes here to send this to yourself]", "Your generated document", "See attachment", | |
{ attachments: [ | |
{fileName: blob.getName(), mimeType: "application/pdf", content: blob.getBytes()} | |
] | |
}); | |
} |
This file contains 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 characters
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import com.google.gson.Gson; | |
public class DownloadPOST { | |
public static void main(String[] args) throws Exception { | |
URL url = new URL("http://www.ultradox.com/ultradoc/execute?id=JaFxzA9G0ac4Npx83lvY78M9kO5lNO&action=DOWNLOAD"); | |
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | |
connection.setRequestMethod("POST"); | |
connection.setRequestProperty("Content-Type", | |
"application/json"); | |
connection.setDoInput(true); | |
connection.setDoOutput(true); | |
Gson gson = new Gson(); | |
Payload payload = new Payload("Sales Representative", "2013-01-31", | |
true); | |
String json = gson.toJson(payload); | |
byte[] bytes = json.getBytes(); | |
connection.setRequestProperty("Content-Length", | |
Integer.toString(bytes.length)); | |
OutputStream os = connection.getOutputStream(); | |
os.write(bytes); | |
os.close(); | |
InputStream inputStream = connection.getInputStream(); | |
FileOutputStream outputStream = new FileOutputStream(new File( | |
"processed.pdf")); | |
transfer(inputStream, outputStream); | |
} | |
private static void transfer(InputStream inputStream, | |
OutputStream outputStream) throws IOException { | |
byte[] buffer = new byte[1024]; | |
int len; | |
while ((len = inputStream.read(buffer)) != -1) { | |
outputStream.write(buffer, 0, len); | |
} | |
} | |
public static class Payload { | |
public String position; | |
public String dateOfInterview; | |
public boolean refused; | |
public Payload() { | |
} | |
public Payload(String position, String dateOfInterview, boolean refused) { | |
this.position = position; | |
this.dateOfInterview = dateOfInterview; | |
this.refused = refused; | |
} | |
} | |
} | |
This file contains 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 characters
<form action="http://www.ultradox.com/ultradoc/execute" target="_blank"> | |
<input type="text" name="position" required placeholder="Position"> | |
<input type="text" name="dateOfInterview" required placeholder="Date of Interview, YYYY-MM-DD"> | |
<input type="text" name="refused" required placeholder="Refused: true / false"> | |
<input type="hidden" name="id" value="JaFxzA9G0ac4Npx83lvY78M9kO5lNO"> | |
<input type="hidden" name="action" value="DOWNLOAD"> | |
<input type="submit" value="Create and Download"> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment