项目作者: ander7agar

项目描述 :
Simple and lightweight HTTP client for Android
高级语言: Java
项目地址: git://github.com/ander7agar/android-http-client.git
创建时间: 2017-01-03T22:16:06Z
项目社区:https://github.com/ander7agar/android-http-client

开源协议:Other

下载


Android HTTP Client


Android Http Client is a small library to make requests to any internet service simple and practical way.
You can implement multiple interfaces for the management of the responses. It also includes interfaces
for managing upload and download of files.

These are the interfaces that includes the library and its use:

  • RequestListener: Capture the events of the start and end of the request.
  • ResponseListener: Capture the response when making the request.

Compatibility:

  • Android SDK: Android Http Client requires a minimum API Level 14
  • Marek Sebera Http Client: Marek Sebera Http Client for Android.
  • JSON: Android Http Client uses JSON Java Library for compatibility json responses.
  • XML: Android Http Client uses Jsoup Library for compatibility xml responses.

How do I use this library:

  1. Request request = Request.create("http://service.server.com/getData");
  2. request.setMethod("POST")
  3. .setTimeout(120) //2 Minutes
  4. .addHeader("Authorization", "Key=MY_SERVICE_KEY")
  5. .addParameter("key1", "value1")
  6. .addParameter("key2", "value3")
  7. .addParameter(new Parameter("key3", "value3"))
  8. .addParameter("file", new File("myfile.txt"))
  9. .setFileUploadListener(new FileUploadListener() {
  10. @Override
  11. public void onUploadingFile(File file, long size, long uploaded) {
  12. }
  13. })
  14. .setRequestStateListener(new RequestStateListener() {
  15. @Override
  16. public void onStart() {
  17. }
  18. @Override
  19. public void onFinish() {
  20. }
  21. @Override
  22. public void onUploadProgress(float progress) {
  23. }
  24. @Override
  25. public void onConnectionError(Exception e) {
  26. e.printStackTrace();
  27. }
  28. })
  29. .setResponseListener(new JsonResponseListener() {
  30. @Override
  31. public void onOkResponse(JSONObject jsonObject) throws JSONException {
  32. }
  33. @Override
  34. public void onErrorResponse(JSONObject jsonObject) throws JSONException {
  35. }
  36. @Override
  37. public void onParseError(JSONException e) {
  38. }
  39. }).execute();

Download:

Gradle:

  1. repositories {
  2. maven { url "https://jitpack.io" }
  3. }
  4. dependencies {
  5. compile 'com.github.ander7agar:android-org.apache.http-client:0.6.1'
  6. }

Maven:

  1. <repositories>
  2. <repository>
  3. <id>jitpack.io</id>
  4. <url>https://jitpack.io</url>
  5. </repository>
  6. </repositories>
  7. <dependency>
  8. <groupId>com.github.ander7agar</groupId>
  9. <artifactId>android-org.apache.http-client</artifactId>
  10. <version>0.6.1</version>
  11. </dependency>

License:

  1. Copyright 2017 Andersson G. Acosta de la Rosa
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. org.apache.http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.