@Test public void testBinary() throws Exception { HttpServer server = HttpServer.create( new InetSocketAddress( 7212 ), 0 ); server.createContext( "/test", new MyHandler2() ); server.setExecutor( null ); server.start(); Thread.sleep( 10 ); byte[] response = HTTP.getBytesWithHeaders( "http: "application/java-archive", Maps.map( "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Encoding", "gzip,deflate,sdch", "Accept-Language", "en-US,en;q=0.8" ) ); boolean ok = true; ok &= response.length == 19 || die( "response is the wrong length" + response.length ); for ( int index = 0; index < 19; index++ ) { ok &= response[ index ] == index || die( sputs( "index", index, "ressponse at index", response[ index ] ) ); } Thread.sleep( 10 ); server.stop( 0 ); }
public static byte[] getBytesWithHeaders( final String url, final String contentType, final Map<String, ?> headers ) { return Exceptions.tryIt( byte[].class, new Exceptions.TrialWithReturn<byte[]>() { @Override public byte[] tryIt() throws Exception { URLConnection connection; connection = doGet( url, headers, contentType, null, true ); return extractResponseBytes( connection ); } } ); }
HTTP { public static byte[] getBytesWithHeaders( final String url, final String contentType, final Map<String, ?> headers ) { return Exceptions.tryIt( byte[].class, new Exceptions.TrialWithReturn<byte[]>() { @Override public byte[] tryIt() throws Exception { URLConnection connection; connection = doGet( url, headers, contentType, null, true ); return extractResponseBytes( connection ); } } ); } }
HTTP { public static byte[] getBytesWithHeaders( final String url, final String contentType, final Map<String, ?> headers ) { return Exceptions.tryIt( byte[].class, new Exceptions.TrialWithReturn<byte[]>() { @Override public byte[] tryIt() throws Exception { URLConnection connection; connection = doGet( url, headers, contentType, null, true ); return extractResponseBytes( connection ); } } ); }  }
HTTP { public static byte[] getBytesWithHeaders( final String url, final String contentType, final Map<String, ?> headers ) { return Exceptions.tryIt( byte[].class, new Exceptions.TrialWithReturn<byte[]>() { @Override public byte[] tryIt() throws Exception { URLConnection connection; connection = doGet( url, headers, contentType, null, true ); return extractResponseBytes( connection ); } } ); }  static String get(
            final String url ); static String post(
            final String url,
            final String body ); static Response getResponse(
            final String url ); static byte[] getBytes(
            final String url, final String contentType ); static byte[] getBytesWithHeaders(
            final String url, final String contentType, final Map<String, ?> headers ); static String getWithHeaders(
            final String url,
            final Map<String, ?> headers ); static String getWithContentType(
            final String url,
            final Map<String, ?> headers,
            final String contentType ); static String getWithCharSet(
            final String url,
            final Map<String, ?> headers,
            final String contentType,
            final String charSet ); static String postText(
            final String url,
            final String body ); static String postBodyTextWithContentType(
            final String url,
            final String contentType,
            final String body ); static String postJSON(
            final String url,
            final String jsonString ); static Response jsonRestCallViaPOST(
            final String url,
            final String jsonString ); static String getJSON(
            final String url,
            final Map<String, ?> headers
    ); static Response jsonRestCallWithHeaders(
            final String url,
            final Map<String, ?> headers
    ); static Response jsonRestCall(
            final String url
    ); static Response postBodyTextWithContentTypeReturnResponse(    final String url,
            final String contentType,
            final String body ); static String getJSONWithParams(
            final String url,
            final Map<String, ?> headers, final Map<String, ?> params
    ); static String postXML(
            final String url,
            final String jsonString ); static String postWithHeaders(
            final String url,
            final Map<String, ?> headers,
            final String body ); static String postWithContentType(
            final String url,
            final Map<String, ?> headers,
            final String contentType,
            final String body ); static String postWithCharset(
            final String url,
            final Map<String, ?> headers,
            final String contentType,
            final String charSet,
            final String body ); static String postForm( final String url, final Map<String, ?> headers,
                                   final Map<String, Object> formData
    ); }
HTTP { public static byte[] getBytesWithHeaders( final String url, final String contentType, final Map<String, ?> headers ) { return Exceptions.tryIt( byte[].class, new Exceptions.TrialWithReturn<byte[]>() { @Override public byte[] tryIt() throws Exception { URLConnection connection; connection = doGet( url, headers, contentType, null, true ); return extractResponseBytes( connection ); } } ); }  static String get(
            final String url ); static String post(
            final String url,
            final String body ); static Response getResponse(
            final String url ); static byte[] getBytes(
            final String url, final String contentType ); static byte[] getBytesWithHeaders(
            final String url, final String contentType, final Map<String, ?> headers ); static String getWithHeaders(
            final String url,
            final Map<String, ?> headers ); static String getWithContentType(
            final String url,
            final Map<String, ?> headers,
            final String contentType ); static String getWithCharSet(
            final String url,
            final Map<String, ?> headers,
            final String contentType,
            final String charSet ); static String postText(
            final String url,
            final String body ); static String postBodyTextWithContentType(
            final String url,
            final String contentType,
            final String body ); static String postJSON(
            final String url,
            final String jsonString ); static Response jsonRestCallViaPOST(
            final String url,
            final String jsonString ); static String getJSON(
            final String url,
            final Map<String, ?> headers
    ); static Response jsonRestCallWithHeaders(
            final String url,
            final Map<String, ?> headers
    ); static Response jsonRestCall(
            final String url
    ); static Response postBodyTextWithContentTypeReturnResponse(    final String url,
            final String contentType,
            final String body ); static String getJSONWithParams(
            final String url,
            final Map<String, ?> headers, final Map<String, ?> params
    ); static String postXML(
            final String url,
            final String jsonString ); static String postWithHeaders(
            final String url,
            final Map<String, ?> headers,
            final String body ); static String postWithContentType(
            final String url,
            final Map<String, ?> headers,
            final String contentType,
            final String body ); static String postWithCharset(
            final String url,
            final Map<String, ?> headers,
            final String contentType,
            final String charSet,
            final String body ); static String postForm( final String url, final Map<String, ?> headers,
                                   final Map<String, Object> formData
    ); static final int DEFAULT_TIMEOUT_SECONDS; static final String APPLICATION_JSON; }