Advanced HTTP Plugin
Last updated
Was this helpful?
Last updated
Was this helpful?
Tested Version:
This plugin defines a global cordova.plugin.http
object, which communicates with HTTP servers. Although the object is in the global scope, it is not available until after the deviceready
event.
In order to use this plugin, please enable AdvancedHTTP
plugin in Monaca Cloud IDE.
Communicate with HTTP servers by using native processes of iOS or Android.
There is the following advantage compared to using fetch API
in Javascript.
CORS restrictions do not apply
This chapter describes the following basic APIs
sendRequest
setDataSerializer
get
post
Send HTTP request to specified url
.
The options
contains following keys.
method
: HTTP method
headers
: HTTP headers
param
: query strings(mainly applicable on get
)
data
: payload data. The format can be defined by serializer
.(applicable on post
, put
, etc.)
serializer
: data format. Refer setDataSerializer
section about the details.
success: callback function for success request.
error: callback function for failure request.
Example:
Set the data format.
Equivalent to specifying in the sendRequest API
's options.serializer
.
Only applicable on POST/PUT/PATCH requests.
Possible values:
"urlencoded"
"json"
"utf8"
"multipart"
"raw"
Example.1: serializer
="urlencoded"
The values key1=123
, key2=abc
are sent as form data.(Equivalent to sending request with Content-Type: application/x-www-form-urlencoded
)
Example.2: serializer
="json"
Send JSON data on payload.
Send GET request.
Equivalent to specifying in the sendRequest API
's options.method = "get"
.
Set query strings as the second argument.
Excample:
Send POST request.
Equivalent to specifying in the sendRequest API
's options.method = "post"
.
Set payload data as the second argument. The format can be specified by setDataSerializer API
.
Example:
AdvancedHTTP
plugin also provides various APIs.
put / patch / delete / head / options
uploadFile / downloadFile
getBasicAuthHeader
useBasicAuth
setRequestTimeout
setConnectTimeout (Android Only)
setReadTimeout (Android Only)
setFollowRedirect
getCookieString
setCookie
clearCookies
setServerTrustMode
setClientAuthMode
removeCookies
Example: Send POST request
fetch API
AdvancedHTTP
We created sample application using the AdvanceHTTP plugin. Please click the following link to import the application to Monaca.
For other keys, see .
See for more information on other parameters.
See for more information on these APIs.