Skip to content

Instantly share code, notes, and snippets.

@twinge
Created September 16, 2009 04:49
Show Gist options
  • Save twinge/187871 to your computer and use it in GitHub Desktop.
Save twinge/187871 to your computer and use it in GitHub Desktop.
public static void postThumbnail() throws IOException, MalformedURLException {
final WebClient webClient = new WebClient();
webClient.addRequestHeader("ACCEPT", "text/xml");
final String userhash = Base64Coder.encodeString("username:password");
webClient.addRequestHeader("Authorization", "Basic " + userhash);
final HtmlPage page1 = (HtmlPage)webClient.getPage("http://www.creativecrash.com/assets/cg_thumbnail");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("thumbnail_form");
final HtmlSubmitInput button = form.getInputByName("commit");
final HtmlTextInput itemId = form.getInputByName("item_id");
itemId.setValueAttribute("11972");
final HtmlFileInput file = form.getInputByName("file");
file.setValueAttribute("/Users/josh/Desktop/picture1.png");
// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click();
System.out.println(page2.getBody());
}
public static void postFormat() throws IOException, MalformedURLException {
final WebClient webClient = new WebClient();
webClient.addRequestHeader("ACCEPT", "text/xml");
final String userhash = Base64Coder.encodeString("username:password");
webClient.addRequestHeader("Authorization", "Basic " + userhash);
final HtmlPage page1 = (HtmlPage)webClient.getPage("http://www.creativecrash.com/formats/new_cg_format");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("format_form");
final HtmlSubmitInput button = form.getInputByName("commit");
final HtmlTextInput itemId = form.getInputByName("file[download_id]");
itemId.setValueAttribute("11972");
final HtmlSelect formatTypeId = form.getSelectByName("file[format_type_id]");
formatTypeId.setSelectedAttribute(formatTypeId.getOption(1), true);
final HtmlTextInput softwareVersion = form.getInputByName("file[version]");
softwareVersion.setValueAttribute("3");
final HtmlFileInput file = form.getInputByName("file[zip]");
file.setValueAttribute("/Users/josh/Desktop/picture1.png");
// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click();
System.out.println(page2.getBody());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment