diff --git a/README.md b/README.md index d975502..a06f62a 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ Please check [CHANGELOG.md](CHANGELOG.md) for details about updating to a new ve The plugin conforms to the Cordova plugin specification, it can be installed using the Cordova / Phonegap command line interface. - phonegap plugin add cordova-plugin-http + phonegap plugin add cordova-plugin-advanced-http - cordova plugin add cordova-plugin-http + cordova plugin add cordova-plugin-advanced-http ## Usage @@ -28,7 +28,7 @@ using the Cordova / Phonegap command line interface. This plugin creates a cordovaHTTP service inside of a cordovaHTTP module. You must load the module when you create your app's module. var app = angular.module('myApp', ['ngRoute', 'ngAnimate', 'cordovaHTTP']); - + You can then inject the cordovaHTTP service into your controllers. The functions can then be used identically to the examples shown below except that instead of accepting success and failure callback functions, each function returns a promise. For more information on promises in AngularJS read the [AngularJS docs](http://docs.angularjs.org/api/ng/service/$q). For more info on promises in general check out this article on [html5rocks](http://www.html5rocks.com/en/tutorials/es6/promises/). Make sure that you load cordova.js or phonegap.js after AngularJS is loaded. ### Not AngularJS @@ -47,12 +47,20 @@ This returns an object representing a basic HTTP Authorization header of the for This sets up all future requests to use Basic HTTP authentication with the given username and password. cordovaHTTP.useBasicAuth("user", "password"); - + ### setHeader Set a header for all future requests. Takes a header and a value. cordovaHTTP.setHeader("Header", "Value"); - + +### setParamSerializer +Set the parameter serializer which will be used for all future POST and PUT requests. Takes a string representing the name of the serializer. + + cordovaHTTP.setParamSerializer("urlencoded"); + +You can choose one of these two: +* `urlencoded`: send parameters as url encoded content in body (content type "application/x-www-form-urlencoded") +* `json`: send parameters as JSON encoded content in body (content type "application/json") ## Async Functions These functions all take success and error callbacks as their last 2 arguments. @@ -69,7 +77,7 @@ As an alternative, you can store your .cer files in the www/certificates folder. }, function() { console.log('error :('); }); - + ### acceptAllCerts Accept all SSL certificates. Or disable accepting all certificates. This defaults to false. @@ -78,7 +86,7 @@ Accept all SSL certificates. Or disable accepting all certificates. This defau }, function() { console.log('error :('); }); - + ### validateDomainName Whether or not to validate the domain name in the certificate. This defaults to true. @@ -87,7 +95,7 @@ Whether or not to validate the domain name in the certificate. This defaults to }, function() { console.log('error :('); }); - + ### post Execute a POST request. Takes a URL, parameters, and headers. @@ -101,7 +109,7 @@ The success function receives a response object with 3 properties: status, data, "Content-Length": "247" } } - + Most apis will return JSON meaning you'll want to parse the data like in the example below: cordovaHTTP.post("https://google.com/", { @@ -120,12 +128,12 @@ Most apis will return JSON meaning you'll want to parse the data like in the exa }, function(response) { // prints 403 console.log(response.status); - - //prints Permission denied + + //prints Permission denied console.log(response.error); }); - - + + #### failure The error function receives a response object with 3 properties: status, error and headers. Status is the HTTP response code. Error is the error response from the server as a string. Headers is an object with the headers. Here's a quick example: @@ -136,7 +144,7 @@ The error function receives a response object with 3 properties: status, error a "Content-Length": "247" } } - + ### get Execute a GET request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure. @@ -148,7 +156,7 @@ Execute a GET request. Takes a URL, parameters, and headers. See the [post](#p }, function(response) { console.error(response.error); }); - + ### uploadFile Uploads a file saved on the device. Takes a URL, parameters, headers, filePath, and the name of the parameter to pass the file along as. See the [post](#post) documentation for details on what is returned on success and failure. @@ -160,7 +168,7 @@ Uploads a file saved on the device. Takes a URL, parameters, headers, filePath, }, function(response) { console.error(response.error); }); - + ### downloadFile Downloads a file and saves it to the device. Takes a URL, parameters, headers, and a filePath. See [post](#post) documentation for details on what is returned on failure. On success this function returns a cordova [FileEntry object](http://cordova.apache.org/docs/en/3.3.0/cordova_file_file.md.html#FileEntry). @@ -170,7 +178,7 @@ Downloads a file and saves it to the device. Takes a URL, parameters, headers, }, { Authorization: "OAuth2: token" }, "file:///somepicture.jpg", function(entry) { // prints the filename console.log(entry.name); - + // prints the filePath console.log(entry.fullPath); }, function(response) {