通过具有SSL和证书的Phonegap连接到Web服务器 [英] Connect to web server via Phonegap with SSL and Certificate
问题描述
我们有一个包含方法的服务器:
- Authorize(login,pass)
它返回certificate.p12文件(PKCS#12)。
此外,服务器有方法,需要授权的证书。 Ruby上的示例如下:
http = Net :: HTTP.new(url.host,url.port)
http.use_ssl = true
http.verify_mode = OpenSSL :: SSL :: VERIFY_NONE
pkcs12 = OpenSSL :: PKCS12.new(File.read('< CERTIFICATE_PATH>') ,'')
http.cert = pkcs12.certificate
http.key = pkcs12.key
req = Net :: HTTP :: Get.new url.path)
result = http.start {| http |
result = http.request(req)
p result.body
}
但是如何在JS上做呢?如何从Phonegap对JS进行方法调用?
我发现的唯一一个解决方案是通过Java和iOS插件,但我不确定他们会工作。
我使用twitter的finagle和akka连接到web服务。你必须学习scala和如何混合java和scala和安装sbt,这将是一个选项,如果你有足够的时间来适应一个学习曲线。 Scala还有一个非常好的api for xml解析。
应用程序配置文件将指定您的安全设置。这是值得探索的。
有很多研究和编码,但它是值得的。从长远来看。
That's all about Phonegap Android and iOS application build on JS.
We have a server with method: - Authorize(login,pass) which return certificate.p12 file (PKCS#12).
Also server has methods, which requires authorization with that certificate. Example on Ruby looks like that:
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
pkcs12 = OpenSSL::PKCS12.new(File.read('<CERTIFICATE_PATH>'),'')
http.cert = pkcs12.certificate
http.key = pkcs12.key
req = Net::HTTP::Get.new(url.path)
result = http.start {|http|
result = http.request(req)
p result.body
}
But how to make that on JS? How make method call's on JS from Phonegap?
The only one solution which I have found: via plugins on Java and iOS, but i'm not sure that they will work. If yes, maybe someone have already made they?
I use twitter's finagle and akka to connect to a webservice. You would have to learn scala and how to mix java with scala and install sbt, which would be an option if you have enough time to accommodate a learning curve. Scala also has a very good api for xml parsing.
An application configuration file would specify your security settings. It is worth exploring.
There is a lot of research and coding involved but it is worth it in the long run.
这篇关于通过具有SSL和证书的Phonegap连接到Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!