Coder Social home page Coder Social logo

droidnetworking's Introduction

DroidNetworking

Most Android apps need to use HTTP to send and receive data. There are many options for network communication in Android. Google recommends using the Apache Http Client for Eclair (2.1) and Froyo (2.2). For Gingerbread (2.3) and newer the HttpURLConnection is recommended. However response caching was not introduced in the HttpURLConnection until Ice Cream Sandwich (4.0) was released.

DroidNetworking is a network library built on top of the Apache Http Client. It has support for response caching, authentication, HTTP and HTTPS and many other features. Best of all, DroidNetworking can be used on Eclair (2.1) and newer. It has a simple API which reduces the amount of code needed for network communication.

Build Status

Features

  • HTTP and HTTPS
  • Compatible with Android 2.1 (API level 7) and later
  • Make asynchronous or synchronous HTTP requests
  • GET, POST, PUT, DELETE and HEAD requests supported
  • Get the response as a string, byte array or input stream
  • HTTP requests happens in a background thread
  • Requests use a threadpool to limit concurrent resource usage
  • Automatic gzip response decoding support
  • Supports Basic Authentication
  • Transparent HTTP response cache
  • Multipart/form-data support

Usage

See the following blog post for examples on how to use DroidNetworking: Introducing DroidNetworking - A network library for Android

Build

DroidNetworking is now using Gradle. If you have Android Studio or Gradle installed on your computer you can type ./gradlew makeJar to build DroidNetworking and create a jar. The jar can be found in droid-networking/build/libs. The latest jar can also be downloaded here

License

Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0

Built on CloudBees

droidnetworking's People

Contributors

netdev avatar sogeticom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

droidnetworking's Issues

HTTP to HTTPS redirections, always to GET

I have detected that POST requests redirected from HTTP to HTTPS are converted to GET requests.

Redirections are ordered by Apache webserver with Redirect directive It produces responses with HTTP status 301 (Moved Permanently):

<VirtualHost myhost.com:80>
    # Force HTTPS:
    Redirect permanent / https://myhost.com/
</VirtualHost>

May be that changing the method is a security feature, or may be a bug. In any case, I have dig into DroidNetworking code and it seems a behavior from the org.apache.http namespace (I am not completly sure).

Weird problem with Content-Type headers / request type

I need to invike a REST service that will output an answer only when the content-type of the request is form-data (specifically, "multipart/form-data") and the request type is POST. I have not full control of it.

I am trying to set the header and invoke with:

Map<String, String> params = new HashMap<String, String>();
HashMap<String, String> headers = new HashMap<String, String>();
params.put("nid", "21"); //I think it's irrelevant, but who knows
headers.put("Content-type", "multipart/form-data");
NetworkEngine.getInstance().setUseCache(false); //to avoid any error due to cache or stuff like that
NetworkOperation operation = NetworkEngine.getInstance().createOperationWithURLString("serviceUrl", params, HttpMethod.POST);
operation.addHeaders(headers);
operation.addParams(params); //doing it twice, just in case
operation.setListener(LoginActivity.this);
NetworkEngine.getInstance().enqueueOperation(operation);

The output by the server (404 service not found) makes me think that the request has not a right header or is not being executed as a POST Request, as it's the same output that I get on Chrome's Postman (https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm) when I invoke the service with a GET/PUT/DELETE request instead of a POST one.

By the way, with LoopJ's AsyncHTTPClient (http://loopj.com/android-async-http/) I get a right answer just by doing this:

AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("nid", "21");
client.addHeader("Content-type", "multipart/form-data");
client.post("serviceUrl", params, new AsyncHttpResponseHandler() {
@OverRide
public void onSuccess(String response) {
System.out.println(response);
}
@OverRide
public void onFailure(Throwable t) {
t.printStackTrace();
}
});
}

Is there any step withing this library execution flow that may cause the headers being lost, or the request being invoked as get/put/delete instead of post?

GET Request no response with parameter of type int

Hey there,

I'm very new to Android development and Java and I am trying out your networking library. I am wondering if I am setting this HashMap up correctly on a GET request that requires a string value and optional int value. If I don't pass an int value I get a response, however, passing the int value I do not get any response back meaning the onComplete and onError methods never fire in my OperationListener.

Is this a correct way to send params with string and int value?

HashMap params = new HashMap();
params.put("search", "myString");
params.put("limit", 2);

POST Request type array

Hey is it possible to POST a parameter of type array? I'm not getting any response when I try to post a JSONArray with JSONObjects. I've also tried an ArrayList of HashMaps.

Example of params:

//params
HashMap params = new HashMap();
params.put("fromDate", "2014-03-20");
params.put("toDate", "2014-03-25");
params.put("rooms", jsonArray);//also tried jsonArray.toString();

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.