{"id":13452686,"url":"https://github.com/kevinsawicki/http-request","last_synced_at":"2026-10-19T01:01:28.529Z","repository":{"id":547583,"uuid":"2622727","full_name":"kevinsawicki/http-request","owner":"kevinsawicki","description":"Java HTTP Request Library","archived":false,"fork":false,"pushed_at":"2023-10-25T22:21:44.000Z","size":1678,"stargazers_count":3376,"open_issues_count":84,"forks_count":824,"subscribers_count":221,"default_branch":"master","last_synced_at":"2026-10-07T02:33:51.984Z","etag":null,"topics":["http","http-client","java"],"latest_commit_sha":null,"homepage":"http://kevinsawicki.github.io/http-request","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinsawicki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-10-21T19:54:58.000Z","updated_at":"2026-10-01T13:42:03.000Z","dependencies_parsed_at":"2024-06-18T16:52:24.303Z","dependency_job_id":"9a9ea1a2-6aaa-4a49-81a6-9e864ed9f21e","html_url":"https://github.com/kevinsawicki/http-request","commit_stats":{"total_commits":443,"total_committers":17,"mean_commits":"26.058823529411764","dds":0.04514672686230248,"last_synced_commit":"2d62a3e9da726942a93cf16b6e91c0187e6c0136"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/kevinsawicki/http-request","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinsawicki%2Fhttp-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinsawicki%2Fhttp-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinsawicki%2Fhttp-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinsawicki%2Fhttp-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinsawicki","download_url":"https://codeload.github.com/kevinsawicki/http-request/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinsawicki%2Fhttp-request/sbom","scorecard":{"id":557339,"data":{"date":"2025-08-11","repo":{"name":"github.com/kevinsawicki/http-request","commit":"2d62a3e9da726942a93cf16b6e91c0187e6c0136"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":1,"reason":"Found 4/29 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T12:43:00.664Z","repository_id":547583,"created_at":"2025-08-20T12:43:00.665Z","updated_at":"2025-08-20T12:43:00.665Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":344872684,"owners_count":38344170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-10-03T21:59:58.778Z","status":"online","status_checked_at":"2026-10-18T02:00:06.448Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","http-client","java"],"created_at":"2024-07-31T08:00:20.406Z","updated_at":"2026-10-19T01:01:28.098Z","avatar_url":"https://github.com/kevinsawicki.png","language":"Java","funding_links":[],"categories":["Java","Index","Libs","III. Network and Integration","网络编程","Programming Languages"],"sub_categories":["Networking","\u003cA NAME=\"Network\"\u003e\u003c/A\u003eNetwork","4. Http and ssh","Java"],"readme":"# Http Request [![Build Status](https://travis-ci.org/kevinsawicki/http-request.svg)](https://travis-ci.org/kevinsawicki/http-request)\n\nA simple convenience library for using a [HttpURLConnection](http://download.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html)\nto make requests and access the response.\n\nThis library is available under the [MIT License](http://www.opensource.org/licenses/mit-license.php).\n\n## Usage\n\nThe http-request library is available from [Maven Central](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.kevinsawicki%22%20AND%20a%3A%22http-request%22).\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.kevinsawicki\u003c/groupId\u003e\n  \u003cartifactId\u003ehttp-request\u003c/artifactId\u003e\n  \u003cversion\u003e6.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nNot using [Maven](http://maven.apache.org/)? Simply copy the [HttpRequest](https://raw.githubusercontent.com/kevinsawicki/http-request/master/lib/src/main/java/com/github/kevinsawicki/http/HttpRequest.java)\nclass into your project, update the package declaration, and you are good to go.\n\nJavadocs are available [here](http://kevinsawicki.github.com/http-request/apidocs/index.html).\n\n## FAQ\n\n### Who uses this?\n\nSee [here](https://github.com/kevinsawicki/http-request/wiki/Used-By) for a\nlist of known projects using this library.\n\n### Why was this written?\n\nThis library was written to make HTTP requests simple and easy when using a `HttpURLConnection`.\n\nLibraries like [Apache HttpComponents](http://hc.apache.org) are great but sometimes\nfor either simplicity, or perhaps for the environment you are deploying to (Android),\nyou just want to use a good old-fashioned `HttpURLConnection`.  This library seeks\nto add convenience and common patterns to the act of making HTTP requests such as\na fluid-interface for building requests and support for features such as multipart\nrequests.\n\n**Bottom line:** The single goal of this library is to improve the usability of the\n`HttpURLConnection` class.\n\n### What are the dependencies?\n\n**None**.  The goal of this library is to be a single class class with some inner static\nclasses.  The test project does require [Jetty](http://eclipse.org/jetty/) in order\nto test requests against an actual HTTP server implementation.\n\n### How are exceptions managed?\n\nThe `HttpRequest` class does not throw any checked exceptions, instead all low-level\nexceptions are wrapped up in a `HttpRequestException` which extends `RuntimeException`.\nYou can access the underlying exception by catching `HttpRequestException` and calling\n`getCause()` which will always return the original `IOException`.\n\n### Are requests asynchronous?\n\n**No**.  The underlying `HttpUrlConnection` object that each `HttpRequest`\nobject wraps has a synchronous API and therefore all methods on `HttpRequest`\nare also synchronous.\n\nTherefore it is important to not use an `HttpRequest` object on the main thread\nof your application.\n\nHere is a simple Android example of using it from an\n[AsyncTask](http://developer.android.com/reference/android/os/AsyncTask.html):\n\n```java\nprivate class DownloadTask extends AsyncTask\u003cString, Long, File\u003e {\n  protected File doInBackground(String... urls) {\n    try {\n      HttpRequest request =  HttpRequest.get(urls[0]);\n      File file = null;\n      if (request.ok()) {\n        file = File.createTempFile(\"download\", \".tmp\");\n        request.receive(file);\n        publishProgress(file.length());\n      }\n      return file;\n    } catch (HttpRequestException exception) {\n      return null;\n    }\n  }\n\n  protected void onProgressUpdate(Long... progress) {\n    Log.d(\"MyApp\", \"Downloaded bytes: \" + progress[0]);\n  }\n\n  protected void onPostExecute(File file) {\n    if (file != null)\n      Log.d(\"MyApp\", \"Downloaded file to: \" + file.getAbsolutePath());\n    else\n      Log.d(\"MyApp\", \"Download failed\");\n  }\n}\n\nnew DownloadTask().execute(\"http://google.com\");\n```\n\n## Examples\n\n### Perform a GET request and get the status of the response\n\n```java\nint response = HttpRequest.get(\"http://google.com\").code();\n```\n\n### Perform a GET request and get the body of the response\n\n```java\nString response = HttpRequest.get(\"http://google.com\").body();\nSystem.out.println(\"Response was: \" + response);\n```\n\n### Print the response of a GET request to standard out\n\n```java\nHttpRequest.get(\"http://google.com\").receive(System.out);\n```\n\n### Adding query parameters\n\n```java\nHttpRequest request = HttpRequest.get(\"http://google.com\", true, 'q', \"baseball gloves\", \"size\", 100);\nSystem.out.println(request.toString()); // GET http://google.com?q=baseball%20gloves\u0026size=100\n```\n\n### Using arrays as query parameters\n\n```java\nint[] ids = new int[] { 22, 23 };\nHttpRequest request = HttpRequest.get(\"http://google.com\", true, \"id\", ids);\nSystem.out.println(request.toString()); // GET http://google.com?id[]=22\u0026id[]=23\n```\n\n### Working with request/response headers\n\n```java\nString contentType = HttpRequest.get(\"http://google.com\")\n                                .accept(\"application/json\") //Sets request header\n                                .contentType(); //Gets response header\nSystem.out.println(\"Response content type was \" + contentType);\n```\n\n### Perform a POST request with some data and get the status of the response\n\n```java\nint response = HttpRequest.post(\"http://google.com\").send(\"name=kevin\").code();\n```\n\n### Authenticate using Basic authentication\n\n```java\nint response = HttpRequest.get(\"http://google.com\").basic(\"username\", \"p4ssw0rd\").code();\n```\n\n### Perform a multipart POST request\n\n```java\nHttpRequest request = HttpRequest.post(\"http://google.com\");\nrequest.part(\"status[body]\", \"Making a multipart request\");\nrequest.part(\"status[image]\", new File(\"/home/kevin/Pictures/ide.png\"));\nif (request.ok())\n  System.out.println(\"Status was updated\");\n```\n\n### Perform a POST request with form data\n\n```java\nMap\u003cString, String\u003e data = new HashMap\u003cString, String\u003e();\ndata.put(\"user\", \"A User\");\ndata.put(\"state\", \"CA\");\nif (HttpRequest.post(\"http://google.com\").form(data).created())\n  System.out.println(\"User was created\");\n```\n\n### Copy body of response to a file\n\n```java\nFile output = new File(\"/output/request.out\");\nHttpRequest.get(\"http://google.com\").receive(output);\n```\n### Post contents of a file\n\n```java\nFile input = new File(\"/input/data.txt\");\nint response = HttpRequest.post(\"http://google.com\").send(input).code();\n```\n\n### Using entity tags for caching\n\n```java\nFile latest = new File(\"/data/cache.json\");\nHttpRequest request = HttpRequest.get(\"http://google.com\");\n//Copy response to file\nrequest.receive(latest);\n//Store eTag of response\nString eTag = request.eTag();\n//Later on check if changes exist\nboolean unchanged = HttpRequest.get(\"http://google.com\")\n                               .ifNoneMatch(eTag)\n                               .notModified();\n```\n\n### Using gzip compression\n\n```java\nHttpRequest request = HttpRequest.get(\"http://google.com\");\n//Tell server to gzip response and automatically uncompress\nrequest.acceptGzipEncoding().uncompress(true);\nString uncompressed = request.body();\nSystem.out.println(\"Uncompressed response is: \" + uncompressed);\n```\n\n### Ignoring security when using HTTPS\n\n```java\nHttpRequest request = HttpRequest.get(\"https://google.com\");\n//Accept all certificates\nrequest.trustAllCerts();\n//Accept all hostnames\nrequest.trustAllHosts();\n```\n\n### Configuring an HTTP proxy\n\n```java\nHttpRequest request = HttpRequest.get(\"https://google.com\");\n//Configure proxy\nrequest.useProxy(\"localhost\", 8080);\n//Optional proxy basic authentication\nrequest.proxyBasic(\"username\", \"p4ssw0rd\");\n```\n\n### Following redirects\n\n```java\nint code = HttpRequest.get(\"http://google.com\").followRedirects(true).code();\n```\n\n### Custom connection factory\n\nLooking to use this library with [OkHttp](https://github.com/square/okhttp)?\nRead [here](https://gist.github.com/JakeWharton/5797571).\n\n```java\nHttpRequest.setConnectionFactory(new ConnectionFactory() {\n\n  public HttpURLConnection create(URL url) throws IOException {\n    if (!\"https\".equals(url.getProtocol()))\n      throw new IOException(\"Only secure requests are allowed\");\n    return (HttpURLConnection) url.openConnection();\n  }\n\n  public HttpURLConnection create(URL url, Proxy proxy) throws IOException {\n    if (!\"https\".equals(url.getProtocol()))\n      throw new IOException(\"Only secure requests are allowed\");\n    return (HttpURLConnection) url.openConnection(proxy);\n  }\n});\n```\n\n## Contributors\n\n* [Kevin Sawicki](https://github.com/kevinsawicki) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=kevinsawicki)\n* [Eddie Ringle](https://github.com/eddieringle) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=eddieringle)\n* [Sean Jensen-Grey](https://github.com/seanjensengrey) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=seanjensengrey)\n* [Levi Notik](https://github.com/levinotik) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=levinotik)\n* [Michael Wang](https://github.com/michael-wang) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=michael-wang)\n* [Julien HENRY](https://github.com/henryju) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=henryju)\n* [Benoit Lubek](https://github.com/BoD) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=BoD)\n* [Jake Wharton](https://github.com/JakeWharton) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=JakeWharton)\n* [Oskar Hagberg](https://github.com/oskarhagberg) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=oskarhagberg)\n* [David Pate](https://github.com/DavidTPate) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=DavidTPate)\n* [Anton Rieder](https://github.com/aried3r) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=aried3r)\n* [Jean-Baptiste Lièvremont](https://github.com/jblievremont) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=jblievremont)\n* [Roman Petrenko](https://github.com/romanzes) :: [contributions](https://github.com/kevinsawicki/http-request/commits?author=romanzes)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinsawicki%2Fhttp-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinsawicki%2Fhttp-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinsawicki%2Fhttp-request/lists"}