public static String httpPost (
        final URL url, final String submission, int timeout, final Map<String, String> requestProps)
        throws IOException, ServiceWaiter.TimeoutException
    {
        final ServiceWaiter<String> waiter = new ServiceWaiter<String>(
            (timeout < 0) ? ServiceWaiter.NO_TIMEOUT : timeout);
        Thread tt = new Thread() {
            @Override public void run () {
                try {
                    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                    conn.setDoInput(true);
                    conn.setDoOutput(true);
                    conn.setUseCaches(false);
                    for (Map.Entry<String, String> entry : requestProps.entrySet()) {
                        conn.setRequestProperty(entry.getKey(), entry.getValue());
                    }

                    DataOutputStream out = new DataOutputStream(conn.getOutputStream());
                    out.writeBytes(submission);
                    out.flush();
                    out.close();

                    BufferedReader reader = new BufferedReader(
                        new InputStreamReader(conn.getInputStream()));

                    StringBuilder buf = new StringBuilder();
                    for (String s; null != (s = reader.readLine()); ) {
                        buf.append(s);
                    }
                    reader.close();

                    waiter.postSuccess(buf.toString()); // yay

                } catch (IOException e) {
                    waiter.postFailure(e); // boo
                }
            }
        };

        tt.start();

        if (waiter.waitForResponse()) {
            return waiter.getArgument();
        } else {
            throw (IOException) waiter.getError();
        }
    }
public static String httpPost ( final URL url , final String submission , int timeout , final Map < String , String > requestProps ) throws IOException , ServiceWaiter . TimeoutException { final ServiceWaiter < String > waiter = new ServiceWaiter < String > ( ( timeout < 0 ) ? ServiceWaiter . NO_TIMEOUT : timeout ) ; Thread tt = new Thread ( ) { @ Override public void run ( ) { try { HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ( ) ; conn . setDoInput ( true ) ; conn . setDoOutput ( true ) ; conn . setUseCaches ( false ) ; for ( Map . Entry < String , String > entry : requestProps . entrySet ( ) ) { conn . setRequestProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } DataOutputStream out = new DataOutputStream ( conn . getOutputStream ( ) ) ; out . writeBytes ( submission ) ; out . flush ( ) ; out . close ( ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( conn . getInputStream ( ) ) ) ; StringBuilder buf = new StringBuilder ( ) ; for ( String s ; null != ( s = reader . readLine ( ) ) ; ) { buf . append ( s ) ; } reader . close ( ) ; waiter . postSuccess ( buf . toString ( ) ) ; } catch ( IOException e ) { waiter . postFailure ( e ) ; } } } ; tt . start ( ) ; if ( waiter . waitForResponse ( ) ) { return waiter . getArgument ( ) ; } else { throw ( IOException ) waiter . getError ( ) ; } }
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 {@code 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.