Framework v4 BETA

HTTP

Cordova / Phonegap plugin for communicating with HTTP servers. Supports iOS and Android.

Advantages over Javascript requests:

  • Background threading - all requests are done in a background thread
  • SSL Pinning

Repo: https://github.com/silkimen/cordova-plugin-advanced-http

Installation

  1. Install the Cordova and Ionic Native plugins:
    shell
    $ ionic cordova plugin add cordova-plugin-advanced-http
    $ npm install --save @ionic-native/[email protected]
    
  2. Add this plugin to your app's module

Supported Platforms

  • Android
  • iOS

Usage

typescript
import { HTTP } from '@ionic-native/http/ngx';

constructor(private http: HTTP) {}

...

this.http.get('http://ionic.io', {}, {})
  .then(data => {

    console.log(data.status);
    console.log(data.data); // data received by server
    console.log(data.headers);

  })
  .catch(error => {

    console.log(error.status);
    console.log(error.error); // error message as string
    console.log(error.headers);

  });


Instance Members

patch

Make a PATCH request

Parameters

url

Type: string
The url to send the request to

body

Type: any
The body of the request

headers

Type: any
The headers to set for this request


clearCookies

Clear all cookies.


post

Make a POST request

Parameters

url

Type: string
The url to send the request to

body

Type: any
The body of the request

headers

Type: any
The headers to set for this request


disableRedirect

Disable following redirects automatically.

Parameters

disable

Type: boolean
Set to true to disable following redirects automatically


delete

Make a DELETE request

Parameters

url

Type: string
The url to send the request to

parameters

Type: any
Parameters to send with the request

headers

Type: any
The headers to set for this request


put

Make a PUT request

Parameters

url

Type: string
The url to send the request to

body

Type: any
The body of the request

headers

Type: any
The headers to set for this request


getBasicAuthHeader

This returns an object representing a basic HTTP Authorization header of the form.

Parameters

username

Type: string
Username

password

Type: string
Password


downloadFile

undefined

Parameters

url

Type: string
The url to send the request to

body

Type: any
The body of the request

headers

Type: any
The headers to set for this request

filePath

Type: string
The path to download the file to, including the file name.


get

Make a GET request

Parameters

url

Type: string
The url to send the request to

parameters

Type: any
Parameters to send with the request

headers

Type: any
The headers to set for this request


setCookie

Add a custom cookie.

Parameters

url

Type: string
Scope of the cookie

cookie

Type: string
RFC compliant cookie string


getRequestTimeout

Get global request timeout value in seconds.


getHeaders

Get all headers defined for a given hostname.

Parameters

host

Type: string
The hostname


getDataSerializer

Get the name of the data serializer which will be used for all future POST and PUT requests.


getCookieString

Resolve cookie string for given URL.

Parameters

url

Type: string


Make a HEAD request

Parameters

url

Type: string
The url to send the request to

parameters

Type: any
Parameters to send with the request

headers

Type: any
The headers to set for this request


removeCookies

Remove cookies for given URL.

Parameters

url

Type: string
undefined

cb


setDataSerializer

Set the data serializer which will be used for all future POST and PUT requests. Takes a string representing the name of the serializer.

Parameters

serializer

Type: string
The name of the serializer. Can be urlencoded, utf8 or json


setHeader

Set a header for all future requests. Takes a hostname, a header and a value.

Parameters

host

Type: string
The hostname to be used for scoping this header

header

Type: string
The name of the header

value

Type: string
The value of the header


setRequestTimeout

Set global request timeout value in seconds.

Parameters

timeout

Type: number
The timeout in seconds. Default 60


setSSLCertMode

Set SSL Cert handling mode, being one of the following values default: default SSL cert handling using system's CA certs nocheck: disable SSL cert checking, trusting all certs (meant to be used only for testing purposes) pinned: trust only provided certs

Parameters

mode

SSL Cert handling mode


uploadFile

undefined

Parameters

url

Type: string
The url to send the request to

body

Type: any
The body of the request

headers

Type: any
The headers to set for this request

filePath

Type: string
The local path of the file to upload

name

Type: string
The name of the parameter to pass the file along as


useBasicAuth

This sets up all future requests to use Basic HTTP authentication with the given username and password.

Parameters

username

Type: string
Username

password

Type: string
Password


HTTPResponse

data

Type: intrinsic
The data that is in the response. This property usually exists when a promise returned by a request method resolves. optional

error

Type: intrinsic
Error response from the server. This property usually exists when a promise returned by a request method rejects. optional

headers

Type: intrinsic
The headers of the response

status

Type: intrinsic
The status number of the response

url

Type: intrinsic
The URL of the response. This property will be the final URL obtained after any redirects.