我正在使用 Titanium Appcelerator 开发适用于 iOS 的应用程序。 我正在努力保护与我的服务器的连接。我购买了 UCC 证书来保护我的服务器(和其他网站)并安装了它。当我继续使用任何浏览器时,它会显示连接是安全的。
现在,当我尝试创建从应用程序到我的服务器的连接时,出现以下错误:
The certificate for this server is invalid. You might be connecting to a server that is pretending to be DOMAIN.COM
我试过其他安全域,效果很好。 我正在使用 Ti.Network.createHTTPClient 来创建我的连接。 有没有人知道这个问题?我在这里遗漏了什么吗?
最佳答案
您应该使用 securityManager
与安全网站进行通信。下面是来自 documentation 的简单示例.证书应作为 DER 二进制格式的 X.509 证书文件提供。
免责声明:appcelerator.https
模块是付费功能!
// Require in the module
var https = require('appcelerator.https'),
securityManager,
httpClient;
// Use the module to create a Security Manager that authenticates the specified URLs
securityManager = https.createX509CertificatePinningSecurityManager([
{
url: "https://dashboard.appcelerator.com",
serverCertificate: "dashboard.appcelerator.com.der"
},
{
url: "https://www.wellsfargo.com",
serverCertificate: "wellsfargo.der"
}
]);
// Create an HTTP client the same way you always have
// but pass in the optional Security Manager that was created previously.
httpClient = Ti.Network.createHTTPClient({
onload: function(e) {
Ti.API.info("Received text: " + this.responseText);
},
onerror: function(e) {
Ti.API.error(e.error);
},
timeout : 5000,
// Set this property before calling the `open` method.
securityManager: securityManager
});
// Prepare the HTTPS connection in the same way you always have
// and the Security Manager will authenticate all servers for
// which it was configured before any communication happens.
httpClient.open("GET", "https://dashboard.appcelerator.com");
// Send the request in the same way you always have.
// Throws a Security Exception if authentication fails.
httpClient.send();
关于ios - 钛 - "The certificate for this server is invalid. You might be connecting to a server that is pretending to be DOMAIN.COM”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32983099/