Easily integrate the most reliable native networking libraries with the latest and greatest HTTPS security features.
Plugin version 2.0.0 bumps
AFNetworking
on iOS to 4.0.0 which no longer relies onUIWebView
. Make sure to runpod repo update
to get the latestAFNetworking
pod on your development machine.
What the flip is SSL pinning and all this security mumbo jumbo?
How to make your apps more secure with SSL pinning.
Do I have to use SSL pinning?
No. This plugin works out of the box without any security configurations needed. Either way you'll still benefit from all the features listed above.
git clone https://github.com/nativescript-community/https
cd https
npm run demo.ios
npm run demo.android
tns-platform-declarations
for Android and iOS to your references.d.ts
!/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
We also recommend adding "skipLibCheck": true,
to your tsconfig.json
.More information on that can be found here.
Install the plugin:
tns plugin add @nativescript-community/https
GET
methodimport * as Https from '@nativescript-community/https';
Https.request({
url: 'https://httpbin.org/get',
method: 'GET',
timeout: 30, // seconds (default 10)
})
.then(function (response) {
console.log('Https.request response', response);
})
.catch(function (error) {
console.error('Https.request error', error);
});
Create a folder called assets
in your projects app
folder like so <project>/app/assets
. Using chrome, go to the URL where the SSL certificate resides. View the details then drag and drop the certificate image into the assets
folder.
import { knownFolders } from 'file-system';
import * as Https from '@nativescript-community/https';
let dir = knownFolders.currentApp().getFolder('assets');
let certificate = dir.getFile('httpbin.org.cer').path;
Https.enableSSLPinning({ host: 'httpbin.org', certificate });
Once you've enabled SSL pinning you CAN NOT re-enable with a different host
or certificate
file.
import * as Https from '@nativescript-community/https';
Https.disableSSLPinning();
All requests after calling this method will no longer utilize SSL pinning until it is re-enabled once again.
There is a new option called useLegacy
. You can set of every request options.When using that option the request will behave more like {N} http module.
content
returned by a request is not the resulting string but an object. It follows HTTPContent format for the most part. You can call toJSON
or toFile
. The only difference is that toFile
returns a Promise<File>
which means that it is async and run in a background thread!content
too allowing you to read its content.By default basic Cookie support is enabled to work like in {N} http
module.In the future more options will be added
import { knownFolders, path } from '@nativescript/core/file-system';
import * as Https from '@nativescript-community/https';
Https.setCache({
diskLocation: path.join(knownFolders.documents().path, 'httpcache'),
diskSize: 10 * 1024 * 1024, // 10 MiB
});
/// later on when calling your request you can use the cachePolicy option
If you set the Content-Type
header to "multipart/form-data"
the request body will be evaluated as a multipart form data. Each body parameter is expected to be in this format:
{
data: any
parameterName: string,
fileName?: string
contentType?: string
}
if fileName
and contentType
are set then data is expected to be either a NSData
on iOS or a native.Array<number>
on Android.
export interface HttpsSSLPinningOptions {
host: string;
certificate: string;
allowInvalidCertificates?: boolean;
validatesDomainName?: boolean;
commonName?: string;
}
import { HttpRequestOptions } from 'tns-core-modules/http';
export interface HttpsRequestOptions extends HTTPOptions {
useLegacy?: boolean;
cachePolicy?: 'noCache' | 'onlyCache' | 'ignoreCache';
onProgress?: (current: number, total: number) => void;
}
SSLPinning Option | Description |
---|---|
host: string |
This must be the request domain name eg sales.company.org . |
commonName?: string |
Default: options.host, set if certificate CN is different from the host eg *.company.org (Android specific) |
certificate: string |
The uri path to your .cer certificate file. |
allowInvalidCertificates?: boolean |
Default: false . This should always be false if you are using SSL pinning. Set this to true if you're using a self-signed certificate. |
validatesDomainName?: boolean |
Default: true . Determines if the domain name should be validated with your pinned certificate. |
Requests Option | Description |
---|---|
useLegacy?: boolean |
Default: false . [IOS only] set to true in order to get the response data (when status >= 300)in the content directly instead of response.body.content . |
`cachePolicy?: 'noCache' | 'onlyCache' |
onProgress?: (current: number, total: number) => void |
[IOS only] Set the progress callback. |
Since you're probably shipping a certificate with your app (like our demo does),make sure it's bundled by Webpack as well. You can do this by adding the certificate(s) with the CopyWebpackPlugin
.
iOS
TroubleshootingApp Transport Security before starting beef!
Please educate yourself on iOS's
If you try and hit an https
route without adding it to App Transport Security's whitelist it will not work!You can bypass this behavior by adding the following to your projects Info.plist
:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
This plugin does not add
NSAllowsArbitraryLoads
to your projectsInfo.plist
for you.
Android
troubleshootingIf you app crashes with a message that it's doing too much networkin on the main thread,then pass the option allowLargeResponse
with value true
to the request
function.
Who | Why |
---|---|
Robert Laverty | For creating and maintaining this plugin for a long time, before transfering it to me, with the help of Jeff Whelpley of GetHuman. |
AFNetworking | AFNetworking A delightful networking framework for iOS, OS X, watchOS, and tvOS. |
Square | okhttp An HTTP+HTTP/2 client for Android and Java applications. |
1.http 和https 的基本概念 HTTP: 超文本传输协议,是互联网上应用最为广泛的一种网络协议,是一个客户端和服务器端请求和应答的标准(TCP),用于从WWW 服务器传输超文本到本地浏览器的传输协议,它可以使浏览器更加高效,使网络传输减少。 HTTPS:HTTPS(Hypertext Transfer Protocol Secure:超文本传输安全协议)是一种透过计算机网络进行安全通信的
HTTPS是什么 (全称:Hyper Text Transfer Protocol over SecureSocket Layer)就是http+ssl,是以安全为目标的 HTTP 通道,在HTTP的基础上通过传输加密和身份认证保证了传输过程的安全性 [1] 。HTTPS 在HTTP 的基础下加入SSL,HTTPS 的安全基础是 SSL,因此加密的详细内容就需要 SSL。 HTTPS
一、https://是什么 HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer 或 Hypertext Transfer Protocol Secure,超文本传输安全协议),是以安全为目标的HTTP通道,简单讲是HTTP 的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL。它是
目录 一、背景 二、Nginx配置方案 三、总结 一、背景 目前Nginx常用的操作就是作为反向代理服务器,还被用于搭建负载均衡,而某些场景下则需要使用正向代理,正向代理的特点如下: 客户端非常明确要访问的服务器地址; 服务器只清楚请求来自哪个代理服务器,而不清楚来自哪个具体的客户端; 正向代理模式屏蔽或者隐藏了真实客户端信息。 常见的情况是,当开发好的应用部署在多台服务器上时,且部
首先看看nginx转发http请求的配置文件: server { listen 80;#代理监听的端口 server_name localhost;#代理的地址 location / { proxy_pass http://www.xxx.com; #需要跳转的地址 }
问题内容: 我在当前的项目中使用它来处理客户端身份验证等。当前它仅打印出客户端地址/端口,以便我可以检查一个TCP连接是否用于多个请求()或是否有新连接为每个请求建立(因此每次都会进行新的SSL握手)。当我使用FireFox对服务器发出多个请求时,我可以看到keep- alive正在运行。因此服务器部分可以很好地处理GET和POST请求。 如果我过去对服务器发出请求(在这种情况下, 不 使用SSL
问题内容: 是的,我的应用程序服务器在https上运行。客户端要求将肥皂地址从http更改为https。 客户要求每当他想要2通过浏览器看到wsdl时,soap地址应为https 我已经在axis2.xml中添加了它… 我在service.xml中添加了以下内容 在关闭标签之后,但它给了我下面的错误。 它给了我例外 问题答案: service.xml中 有一个错字。它应该是 : 不是HTTPS。
问题内容: 我目前正在尝试使用进行多个请求。 我用谷歌搜索了如何做到这一点,答案是使用。 至此,我得到了: 然后我尝试了一个请求,并且一切正常。 然后,我通过cmd创建了一个信任库,并导入了目标网站的证书,使用我的信任库设置并设置的of : 如果我尝试执行Https,则会出现异常。 如果我做同样的事情,但一切正常。 谁能告诉我如何使它起作用?(不用担心,我不会创建任何ddos工具) 提前致谢! P
问题内容: 我想从Java代码登录到应用程序。这是我的代码… 但我无法登录,它只返回登录页面。 如果有人可以,请帮助我了解我在做什么错。 问题答案: 错误 :-( www-form 中间有多余的空格) 正确
问题内容: 我正在开发一个从Web服务器下载数据的应用程序,一开始似乎没有任何问题,但是几天前我开始收到这种异常:javax.net.ssl.SSLException: Read error: ssl=0x7a6588: I/O error during system call, Connection reset by peer我不确定是什么原因引起的问题以及如何解决。这是整个LogCat消息:
问题内容: 的和的方法有什么区别? 任何人都可以通过实时示例来举例说明这些方法以及最佳用法吗? 问题答案: 重定向是一种发送回客户端的响应,而转发委托完全在服务器端进行,转发操作的结果将返回给客户端,就好像它仅来自原始URL。 另一个区别是前向委派只能用于应用程序内资源,而重定向命令可以将客户端浏览器重定向到当前域之外。 例子: 在这里可以找到另一个很好的解释: sendRedirect()和fo
问题内容: 我正在建立正则表达式以检查单词是否以或或开头,我的代码如下, 它打印。我还检查了Regex之后的 stackoverflow,以测试字符串是否以http://或https://开头 正则表达式似乎是正确的,但为什么不匹配?我甚至尝试和 问题答案: 您需要在此处进行 完整的输入 匹配。 编辑 :(基于@davidchambers的评论)
问题内容: 我正在开发一个项目,该项目正在创建一个类来运行http客户端请求(我的类充当客户端)。它接受一个url和一个请求方法(GET,POST,PUT等),我希望能够解析该URL并根据它是https还是http打开HttpsURLConnection或HttpURLConnection(假定给定的url始终是正确)。 如果我执行以下操作: 然后,这将自动创建一个可以同时接受http和https