在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:silkimen/cordova-plugin-advanced-http开源软件地址:https://github.com/silkimen/cordova-plugin-advanced-http开源编程语言:JavaScript 47.2%开源软件介绍:Cordova Advanced HTTPCordova / Phonegap plugin for communicating with HTTP servers. Supports iOS, Android and Browser. This is a fork of Wymsee's Cordova-HTTP plugin. Advantages over Javascript requests
UpdatesPlease check CHANGELOG.md for details about updating to a new version. InstallationThe plugin conforms to the Cordova plugin specification, it can be installed using the Cordova / Phonegap command line interface. phonegap plugin add cordova-plugin-advanced-http
cordova plugin add cordova-plugin-advanced-http Plugin Preferences
e.g. blacklist <preference name="AndroidBlacklistSecureSocketProtocols" value="SSLv3,TLSv1" /> Currently known issues
UsagePlain CordovaThis plugin registers a global object located at With Ionic-native wrapperCheck the Ionic docs for how to use this plugin with Ionic-native. Synchronous FunctionsgetBasicAuthHeaderThis returns an object representing a basic HTTP Authorization header of the form var header = cordova.plugin.http.getBasicAuthHeader('user', 'password'); useBasicAuthThis sets up all future requests to use Basic HTTP authentication with the given username and password. cordova.plugin.http.useBasicAuth('user', 'password'); setHeaderSet a header for all future requests to a specified host. Takes a hostname, a header and a value (must be a string value or null). cordova.plugin.http.setHeader('Hostname', 'Header', 'Value'); You can also define headers used for all hosts by using wildcard character "*" or providing only two params. cordova.plugin.http.setHeader('*', 'Header', 'Value');
cordova.plugin.http.setHeader('Header', 'Value'); The hostname also includes the port number. If you define a header for // will match http://www.example.com/...
cordova.plugin.http.setHeader('www.example.com', 'Header', 'Value');
// will match http://www.example.com:8080/...
cordova.plugin.http.setHeader('www.example.com:8080', 'Header', 'Value'); setDataSerializerSet the data serializer which will be used for all future PATCH, POST and PUT requests. Takes a string representing the name of the serializer. cordova.plugin.http.setDataSerializer('urlencoded'); You can choose one of these:
This defaults to
setRequestTimeoutSet how long to wait for a request to respond, in seconds. For Android, this will set both connectTimeout and readTimeout. For iOS, this will set timeout interval. For browser platform, this will set timeout. cordova.plugin.http.setRequestTimeout(5.0); setConnectTimeout (Android Only)Set connect timeout for Android cordova.plugin.http.setRequestTimeout(5.0); setReadTimeout (Android Only)Set read timeout for Android cordova.plugin.http.setReadTimeout(5.0); setFollowRedirectConfigure if it should follow redirects automatically. This defaults to true. cordova.plugin.http.setFollowRedirect(true); getCookieStringReturns saved cookies (as string) matching given URL. cordova.plugin.http.getCookieString(url); setCookieAdd a custom cookie. Takes a URL, a cookie string and an options object. See ToughCookie documentation for allowed options. cordova.plugin.http.setCookie(url, cookie, options); clearCookiesClear the cookie store. cordova.plugin.http.clearCookies(); Asynchronous FunctionsThese functions all take success and error callbacks as their last 2 arguments. setServerTrustModeSet server trust mode, being one of the following values:
To use SSL pinning you must include at least one // enable SSL pinning
cordova.plugin.http.setServerTrustMode('pinned', function() {
console.log('success!');
}, function() {
console.log('error :(');
});
// use system's default CA certs
cordova.plugin.http.setServerTrustMode('default', function() {
console.log('success!');
}, function() {
console.log('error :(');
});
// disable SSL cert checking, only meant for testing purposes, do NOT use in production!
cordova.plugin.http.setServerTrustMode('nocheck', function() {
console.log('success!');
}, function() {
console.log('error :(');
}); setClientAuthModeConfigure X.509 client certificate authentication. Takes mode and options.
// enable client auth using PKCS12 container given in ArrayBuffer `myPkcs12ArrayBuffer`
cordova.plugin.http.setClientAuthMode('buffer', {
rawPkcs: myPkcs12ArrayBuffer,
pkcsPassword: 'mySecretPassword'
}, success, fail);
// enable client auth using certificate in system store (only on Android)
cordova.plugin.http.setClientAuthMode('systemstore', {}, success, fail);
// disable client auth
cordova.plugin.http.setClientAuthMode('none', {}, success, fail); removeCookiesRemove all cookies associated with a given URL. cordova.plugin.http.removeCookies(url, callback); sendRequestExecute a HTTP request. Takes a URL and an options object. This is the internally used implementation of the following shorthand functions (post, get, put, patch, delete, head, uploadFile and downloadFile). You can use this function, if you want to override global settings for each single request. Check the documentation of the respective shorthand function for details on what is returned on success and failure.
The options object contains following keys:
Here's a quick example: const options = {
method: 'post',
data: { id: 12, message: 'test' },
headers: { Authorization: 'OAuth2: token' }
};
cordova.plugin.http.sendRequest('https://google.com/', options, function(response) {
// prints 200
console.log(response.status);
}, function(response) {
// prints 403
console.log(response.status);
//prints Permission denied
console.log(response.error);
}); postExecute a POST request. Takes a URL, data, and headers. cordova.plugin.http.post('https://google.com/', {
test: 'testString'
}, {
Authorization: 'OAuth2: token'
}, function(response) {
console.log(response.status);
}, function(response) {
console.error(response.error);
}); successThe success function receives a response object with 4 properties: status, data, url, and headers. status is the HTTP response code as numeric value. data is the response from the server as a string. url is the final URL obtained after any redirects as a string. headers is an object with the headers. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase. Here's a quick example: {
status: 200,
data: '{"id": 12, "message": "test"}',
url: 'http://example.net/rest'
headers: {
'content-length': '247'
}
} Most apis will return JSON meaning you'll want to parse the data like in the example below: cordova.plugin.http.post('https://google.com/', {
id: 12,
message: 'test'
}, { Authorization: 'OAuth2: token' }, function(response) {
// prints 200
console.log(response.status);
try {
response.data = JSON.parse(response.data);
// prints test
console.log(response.data.message);
} catch(e) {
console.error('JSON parsing error');
}
}, function(response) {
// prints 403
console.log(response.status);
//prints Permission denied
console.log(response.error);
}); failureThe error function receives a response object with 4 properties: status, error, url, and headers (url and headers being optional). status is a HTTP response code or an internal error code. Positive values are HTTP status codes whereas negative values do represent internal error codes. error is the error response from the server as a string or an internal error message. url is the final URL obtained after any redirects as a string. headers is an object with the headers. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase. Here's a quick example: {
status: 403,
error: 'Permission denied',
url: 'http://example.net/noperm'
headers: {
'content-length': '247'
}
}
getExecute a GET request. Takes a URL, parameters, and headers. See the post documentation for details on what is returned on success and failure. 全部评论
专题导读
上一篇:trusche/httplog: Log outgoing HTTP requests in ruby发布时间:2022-06-17下一篇:JuliaWeb/HTTP.jl: HTTP for Julia发布时间:2022-06-17热门推荐
热门话题
阅读排行榜
|
请发表评论