简体   繁体   English

使用PhoneGap在Web服务中进行安全通信

[英]Secure communication in a web-service using PhoneGap

I am going to develop a PhoneGap application which is pretty simple. 我将开发一个非常简单的PhoneGap应用程序。
I need to implement an authentication and some simple data transfer from the phone to the server and vice versa. 我需要实现身份验证以及从电话到服务器的一些简单数据传输,反之亦然。
I prefer to use ASP.NET as a webservice and our database is MS SQL, but I am not sure what approach I should take to create a secure communication between PhoneGap App and the webservice. 我更喜欢将ASP.NET用作Web服务,而我们的数据库是MS SQL,但是我不确定应该采用哪种方法在PhoneGap App和Web服务之间创建安全的通信。
The problem with a simple AJAX request is limitation in cross-domain and I'm not sure if JSONP is a good option. 一个简单的AJAX请求的问题是跨域限制,我不确定JSONP是否是一个好选择。

I was wondering if someone can tell me what technology I should use in order to make a semi secure connection which works with PhoneGap (HTML5, JavaScript) and .NET webservice. 我想知道是否有人可以告诉我应该使用什么技术来建立与PhoneGap(HTML5,JavaScript)和.NET Web服务一起使用的半安全连接。
I understand that it's a general question but I need to know what technology is the best in such a case. 我知道这是一个普遍的问题,但是我需要知道在这种情况下哪种技术是最好的。

Thanks. 谢谢。

对于初学者,您可以使用rest接口和http身份验证,这将很简单,并且可以帮助您入门。

JSONP is a good option as long as you sanitize(validate) the input you receive from your request. JSONP是一个不错的选择,只要您清理(验证)从请求中收到的输入即可。 Furthermore its supported from jquery so you could use something like: 此外,它受jquery的支持,因此您可以使用以下命令:

function retrieve(parameter1,parameter2, server) 
{
var url1 = 'http://' + server + '/endpoint.php?jsoncallback=?';
$.getJSON(url1,
          {
            param1: parameter1, 
            param2: parameter2, 
          },

          function(data) 
          {
              console.log('Data connection OK');
              retData = data;
          });
}

Regarding security, you could do this request over HTTPS. 关于安全性,您可以通过HTTPS发出此请求。

At server side, the json reply should be wrapped in a function with the name taken from jsoncallback so you could achieve JSONP. 在服务器端,应将json回复包装在一个具有jsoncallback名称的函数中,以便可以实现JSONP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM