public void asyncPostBytes ( final String url , final String mediaType , final Supplier < byte [ ] > supplier , final Callback callback ) { final String url2 = requireNonNull ( trimToNull ( url ) , "A non-empty URL expected" ) ; final String mediaType2 = requireNonNull ( trimToNull ( mediaType ) , "A non-empty media type expected" ) ; requireNonNull ( supplier , "A valid supplier expected" ) ; requireNonNull ( callback , "A valid callback expected" ) ; // prepare request final Request request = new Request . Builder ( ) . url ( url2 ) . post ( new RequestBody ( ) { @ Override public MediaType contentType ( ) { return MediaType . parse ( mediaType2 + "; charset=utf-8" ) ; } @ Override public void writeTo ( final BufferedSink sink ) throws IOException { sink . write ( supplier . get ( ) ) ; } } ) . build ( ) ; // submit request client . newCall ( request ) . enqueue ( callback ) ; }
Posts the content of a buffer of bytes to a server via a HTTP POST request .