diff --git a/src/main/java/com/samskivert/net/HttpPostUtil.java b/src/main/java/com/samskivert/net/HttpPostUtil.java index 2b6cc4ba..d6aa5c81 100644 --- a/src/main/java/com/samskivert/net/HttpPostUtil.java +++ b/src/main/java/com/samskivert/net/HttpPostUtil.java @@ -13,6 +13,9 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Collections; +import java.util.Map; + import com.samskivert.util.ServiceWaiter; /** @@ -28,7 +31,23 @@ public class HttpPostUtil * @param submission the entire submission eg "foo=bar&baz=boo&futz=foo". * @param timeout time to wait for the response, in seconds, or -1 for forever. */ - public static String httpPost (final URL url, final String submission, int timeout) + public static String httpPost (URL url, String submission, int timeout) + throws IOException, ServiceWaiter.TimeoutException + { + return httpPost(url, submission, timeout, Collections.emptyMap()); + } + + /** + * Return the results of a form post. Note that the http request takes place on another + * thread, but this thread blocks until the results are returned or it times out. + * + * @param url from which to make the request. + * @param submission the entire submission eg "foo=bar&baz=boo&futz=foo". + * @param timeout time to wait for the response, in seconds, or -1 for forever. + * @param requestProps additional request properties. + */ + public static String httpPost ( + final URL url, final String submission, int timeout, final Map requestProps) throws IOException, ServiceWaiter.TimeoutException { final ServiceWaiter waiter = new ServiceWaiter( @@ -41,6 +60,9 @@ public class HttpPostUtil conn.setDoOutput(true); conn.setUseCaches(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + for (Map.Entry entry : requestProps.entrySet()) { + conn.setRequestProperty(entry.getKey(), entry.getValue()); + } DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.writeBytes(submission);