{"id":10279347,"url":"https://github.com/turbomanage/basic-http-client","last_synced_at":"2025-07-22T15:38:38.227Z","repository":{"id":28584100,"uuid":"32102161","full_name":"turbomanage/basic-http-client","owner":"turbomanage","description":"Automatically exported from code.google.com/p/basic-http-client","archived":false,"fork":false,"pushed_at":"2025-06-27T17:26:30.000Z","size":1349,"stargazers_count":74,"open_issues_count":5,"forks_count":25,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-27T18:32:28.618Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/turbomanage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-12T20:58:39.000Z","updated_at":"2025-06-27T17:26:27.000Z","dependencies_parsed_at":"2023-01-14T09:06:46.586Z","dependency_job_id":null,"html_url":"https://github.com/turbomanage/basic-http-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/turbomanage/basic-http-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbomanage%2Fbasic-http-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbomanage%2Fbasic-http-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbomanage%2Fbasic-http-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbomanage%2Fbasic-http-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/turbomanage","download_url":"https://codeload.github.com/turbomanage/basic-http-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turbomanage%2Fbasic-http-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266521912,"owners_count":23942536,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":[],"created_at":"2024-05-26T02:25:12.948Z","updated_at":"2025-07-22T15:38:38.195Z","avatar_url":"https://github.com/turbomanage.png","language":"Java","readme":"[JavaDoc] (http://javadoc.basic-http-client.googlecode.com/git/docs/index.html) | [Blog post](http://turbomanage.wordpress.com/2012/06/12/a-basic-http-client-for-android-and-more/)\n\n#Basic HTTP Client for Java (including App Engine and Android)#\n\nA minimal HTTP client that uses java.net.HttpURLConnection to make requests. It features a simple interface for making Web requests. There is also an [AsyncHttpClient](https://github.com/turbomanage/basic-http-client/blob/master/http-client-java/src/main/java/com/turbomanage/httpclient/AsyncHttpClient.java) which supports making asynchronous requests with retries and exponential backoff, and [AndroidHttpClient](https://github.com/turbomanage/basic-http-client/blob/master/http-client-android/src/main/java/com/turbomanage/httpclient/android/AndroidHttpClient.java) which wraps requests in an Android [AsyncTask](http://developer.android.com/reference/android/os/AsyncTask.html) so that requests can be safely initiated from the UI thread.\n\n##Lightning Start##\n  1. Download one of the jars at left and add it to your lib or libs (Android) folder\n  1. (Android only) Add `\u003cuses-permission android:name=\"android.permission.INTERNET\" /\u003e` to !AndroidManifest.xml\n\n##Quick Start##\n  1. `git clone https://github.com/turbomanage/basic-http-client.git`\n  1. In Eclipse, Import | Existing Projects into Workspace and point it to the basic-http-client dir\n  1. To include the library in another project, add the basic-http-client project to the build path OR\n  1. For Android projects, create a linked source folder named httpclient-src that points to basic-http-client/src\n\n## Maven ##\nIn your Java project (including App Engine for Java), add this to your pom.xml:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.turbomanage.basic-http-client\u003c/groupId\u003e\n    \u003cartifactId\u003ehttp-client-java\u003c/artifactId\u003e\n    \u003cversion\u003e0.89\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Gradle (Android) ##\nIf your Android project builds with Gradle, add this to your app's gradle.build:\n```gradle\ndependencies {\n    ...\n    implementation 'com.turbomanage.basic-http-client:http-client-android:0.89'\n}\n```\n\n##Basic Usage##\n```java\n// Example code to login to App Engine dev server\npublic void loginDev(String userEmail) {\n    BasicHttpClient httpClient = new BasicHttpClient(\"http://localhost:8888\");\n    ParameterMap params = httpClient.newParams()\n            .add(\"continue\", \"/\")\n            .add(\"email\", userEmail)\n            .add(\"action\", \"Log In\");\n    httpClient.addHeader(\"name\", \"value\");\n    httpClient.setConnectionTimeout(2000);\n    HttpResponse httpResponse = httpClient.post(\"/_ah/login\", params);\n}\n\n// Example code to log in to App Engine production app\npublic void loginProd(String authToken) {\n    BasicHttpClient httpClient = new BasicHttpClient(\"http://localhost:8888\");\n    ParameterMap params = httpClient.newParams()\n            .add(\"auth\", authToken);\n    HttpResponse httpResponse = httpClient.get(\"/_ah/login\", params);\n    System.out.println(httpResponse.getBodyAsString());\n}\n```\n##Making Asynchronous Requests##\nThe project includes an !AsyncTask wrapper for Android so that requests can be safely initiated on the UI thread with a callback. Example:\n```java\nAndroidHttpClient httpClient = new AndroidHttpClient(\"http://192.168.1.1:8888\");\nhttpClient.setMaxRetries(5);\nParameterMap params = httpClient.newParams()\n        .add(\"continue\", \"/\")\n        .add(\"email\", \"test@example.com\")\n        .add(\"action\", \"Log In\");\nhttpClient.post(\"/_ah/login\", params, new AsyncCallback() {\n    @Override\n    public void onSuccess(HttpResponse httpResponse) {\n        System.out.println(httpResponse.getBodyAsString());\n    }\n    @Override\n    public void onError(Exception e) {\n        e.printStackTrace();\n    }\n});\n```\n\n## App Engine for Java ##\nThe basic-http-client project simply wraps `java.net.UrlConnection`. On App Engine, this in turn wraps the App Engine URLFetch API. The net result is that you can use version 0.89 or later to make outbound requests from your server application.\n\n## Cookies ##\nIn [AndroidHttpClient](https://github.com/turbomanage/basic-http-client/blob/master/http-client-android/src/main/java/com/turbomanage/httpclient/android/AndroidHttpClient.java), `java.net.CookieManager` is enabled by default above API version 8 (when it was introduced) in order to save cookies between requests and resend them just like a browser does.\n\nPrior to version 0.89, `BasicHttpClient` would also automatically enable `java.net.CookieManager`. However, this is not supported on App Engine, so in version 0.89 and later, you must explicitly enable cookie support. Before making the first request, simply call the static method\n```java\nAbstractHttpClient.ensureCookieManager();\n```\n\n##Understanding the Code##\nThe key method is [AbstractHttpClient](https://github.com/turbomanage/basic-http-client/blob/master/http-client-java/src/main/java/com/turbomanage/httpclient/AbstractHttpClient.java).doHttpMethod(String path, [HttpMethod](https://github.com/turbomanage/basic-http-client/blob/master/http-client-java/src/main/java/com/turbomanage/httpclient/HttpMethod.java) httpMethod, String contentType, byte[] content). This is the method that actually drives each request, catches any exceptions, and rethrows them wrapped in an [HttpRequestException](https://github.com/turbomanage/basic-http-client/blob/master/http-client-java/src/main/java/com/turbomanage/httpclient/HttpRequestException.java). It delegates most of the request lifecycle to a [RequestHandler](https://github.com/turbomanage/basic-http-client/blob/master/http-client-java/src/main/java/com/turbomanage/httpclient/RequestHandler.java) instance. To override the default behaviors (say, to provide your own error handler or custom stream reader/writer), simply extend the [BasicRequestHandler](https://github.com/turbomanage/basic-http-client/blob/master/http-client-java/src/main/java/com/turbomanage/httpclient/BasicRequestHandler.java) like this:\n\n```java\n        BasicHttpClient client = new BasicHttpClient(baseUrl, new BasicRequestHandler() {\n            @Override\n            public boolean onError(HttpResponse res, Exception e) {\n                e.printStackTrace();\n                return true; // if recoverable\n            }\n        });\n```\n\n##Advanced Usage##\nTo create an async client for another platform, simply subclass [AsyncHttpClient](https://github.com/turbomanage/basic-http-client/blob/master/http-client-java/src/main/java/com/turbomanage/httpclient/AsyncHttpClient.java) and provide it with an instance of a [AsyncRequestExecutorFactory](https://github.com/turbomanage/basic-http-client/blob/master/http-client-java/src/main/java/com/turbomanage/httpclient/AsyncRequestExecutorFactory.java) suitable for your platform. See the com.turbomanage.httpclient.android package for the Android implementation which uses [AsyncTask](http://developer.android.com/reference/android/os/AsyncTask.html).\n","funding_links":[],"categories":["Networking","网络编程"],"sub_categories":["Spring Cloud框架"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturbomanage%2Fbasic-http-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fturbomanage%2Fbasic-http-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturbomanage%2Fbasic-http-client/lists"}