HTTP GET & POST Parameters - leocadiotine/Dumbledroid GitHub Wiki
It's possible to pass parameters to the request and specify the HTTP method when loading a Model
using Dumbledroid. This page will show you how.
##Passing HTTP parameters to the request
The best way to achieve this is to make your own implementation of the load()
method on your models. The load()
method from AbstractModel
accepts a list of HTTP parameters as an argument.
Here's a code excerpt from DumbledroidExample
:
public class FlickrPhotos extends AbstractModel {
public FlickrPhotos() {
super("https://secure.flickr.com/services/feeds/photos_public.gne");
}
public void load(Context ctx, String query) throws Exception {
List<NameValuePair> params = new Vector<NameValuePair>();
params.add( new BasicNameValuePair("format", "json") );
params.add( new BasicNameValuePair("tags", query) );
super.load(ctx, params);
}
}
If you call load(myActivity, "android")
, Dumbledroid will pass the parameters to the request and will mount an URL like this:
https://secure.flickr.com/services/feeds/photos_public.gne?format=json&tags=android
##Choosing between GET and POST
You can choose between GET and POST requests simply by specifying a third parameter to super.load()
:
super.load(ctx, params, HttpMethod.GET);
// or
super.load(ctx, params, HttpMethod.POST);
The default HTTP method on Dumbledroid is GET
.