Android 如何在移动应用程序上连接到服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23866919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:32:57  来源:igfitidea点击:

How to connect to the server on mobile application?

androidjquery-mobilemobile-applicationkendo-mobileappframework

提问by deadshot

I am new to mobile applications. I am basically from a web development platform. I am just playing around mobile frameworks like App Framework, LungoJS, Jquery Mobile, kendo etc to gain some knowledge in this vertical.

我是移动应用程序的新手。我基本上来自一个网络开发平台。我只是在玩移动框架,如 App Framework、LungoJS、Jquery Mobile、kendo 等,以获取该垂直领域的一些知识。

The app I am developing is still in UI level. All I need is to fetch data from the server and populate in my app.

我正在开发的应用程序仍处于 UI 级别。我所需要的只是从服务器获取数据并填充到我的应用程序中。

I need some ideas to establish server communication between the smart device and the server. My questions are

我需要一些想法来在智能设备和服务器之间建立服务器通信。我的问题是

  1. What kind of server needed for mobile applications ? A cloud or a regular web server is enough ?
  2. What are the ways to connect the app with the server ? ( on cross platform mobile development )
  3. What is the secure way to communication with the server ?
  1. 移动应用程序需要什么样的服务器?云或常规 Web 服务器就足够了?
  2. 应用与服务器连接的方式有哪些?(关于跨平台移动开发)
  3. 与服务器通信的安全方式是什么?

回答by Gajotres

What kind of server needed for mobile applications ? A cloud or a regular web server is enough ?

移动应用程序需要什么样的服务器?云或常规 Web 服务器就足够了?

Because you are creating a hybrid mobile application you can use any type of server side technology, it doesn't matter is it a classic web server technology (using Java, PHP or .NET) or some kind of cloud technology like Parse.com.

因为您正在创建一个混合移动应用程序,所以您可以使用任何类型的服务器端技术,它是经典的 Web 服务器技术(使用 Java、PHP 或 .NET)还是某种云技术(如Parse.com)并不重要

You also don't need to create anything from scratch. Best course of action would be to use some kind of micro RESTFul framework(like PHP Falconor Java Play Framework). Read more about them here.

您也不需要从头开始创建任何东西。最好的做法是使用某种微型 RESTFul 框架(如 PHP Falcon或 Java Play Framework)。在此处阅读有关它们的更多信息。

But, there's always a but. You can't use server side technology for classic content generation, you only need to use it to send data to your hybrid application. I will explain this later.

但是,总有一个但是。您不能使用服务器端技术来生成经典内容,您只需要使用它来将数据发送到您的混合应用程序。我稍后会解释这一点。

There's also an alternative to RESTFul services, you can create a webservice, again using Java, PHP or .NET.

还有一个 RESTFul 服务的替代方案,您可以创建一个 web 服务,同样使用 Java、PHP 或 .NET。

What are the ways to connect the app with the server ? ( on cross platform mobile development )

应用与服务器连接的方式有哪些?(关于跨平台移动开发)

You would use AJAX as a technology (in case of RESTFul), rest depends on you. You would probably do it in JSON format (or JSONP if you are doing cross-domain calls, but you don't need to think about JSONP when creating a hybrid application).

您将使用 AJAX 作为一种技术(在 RESTFul 的情况下),其余取决于您。您可能会以 JSON 格式(或 JSONP,如果您正在执行跨域调用,但在创建混合应用程序时不需要考虑 JSONP)。

If you intend to use a web service then you would use a SOAP connection and communicate via XML format.

如果您打算使用 Web 服务,那么您将使用 SOAP 连接并通过 XML 格式进行通信。

No matter which server side technology you use you will always use AJAX on a client side.

无论您使用哪种服务器端技术,您都将始终在客户端使用 AJAX。

Now let me tell you why you should not generate your content on server side. Basically nothing can prevent you from doing that, you can generate your complete page on web server and just show it in PhoneGap app, it would still be a hybrid app. But, if you try to put this app in Apple store you will get yourself rejected.

现在让我告诉您为什么不应该在服务器端生成内容。基本上没有什么可以阻止你这样做,你可以在网络服务器上生成你的完整页面,然后在 PhoneGap 应用程序中显示它,它仍然是一个混合应用程序。但是,如果您尝试将此应用程序放入 Apple 商店,您将被拒绝。

What is the secure way to communication with the server ?

与服务器通信的安全方式是什么?

Security of course depends on server side technology. Every framework has its own kind of security handling, but all of them relay on HTTPS so you should not worry too much.

安全性当然取决于服务器端技术。每个框架都有自己的安全处理方式,但它们都在 HTTPS 上进行中继,因此您不必太担心。

From the client side you can always encrypt JSON/XML data and send them using POST.

从客户端,您始终可以加密 JSON/XML 数据并使用 POST 发送它们。

Examples:

例子:

If you want to use jQuery Mobile then take a look at thistutorial. It will show you basics of client - server side communication.

如果您想使用 jQuery Mobile,请查看教程。它将向您展示客户端 - 服务器端通信的基础知识。

回答by Sarim Sidd

Since you are new to mobile application, ill try to give short answers

由于您不熟悉移动应用程序,因此我尝试给出简短的答案

1) What kind of server needed for mobile applications ? A cloud or a regular web server is enough ?

1) 移动应用需要什么样的服务器?云或常规 Web 服务器就足够了?

A regular web server is good.

一个普通的网络服务器很好。

2) What are the ways to connect the app with the server ?

2) 应用与服务器连接的方式有哪些?

via web-services

通过网络服务

3) What is the secure way to communication with the server ?

3)与服务器通信的安全方式是什么?

Use HTTPS webservices (SOAP, REST), HTTPS secures the transmission.

使用 HTTPS 网络服务(SOAP、REST),HTTPS 保护传输。

Above is a basic explanation for your quick help, I would recommend you to go through the documentation, and review some sample codes

以上是为您提供快速帮助的基本说明,我建议您阅读文档,并查看一些示例代码

This will really help you Sample

这将真正帮助您样品

回答by Android is everything for me

Please go through this link it will surely help you

请通过此链接,它肯定会对您有所帮助

http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

Webserver,cloud anything is good for restful service

网络服务器,云任何东西都有利于宁静的服务

for security purpose you can use POST parameter to send and recieve data or if you want more security then you can encrypt and decrypt data through secure algorithm

出于安全目的,您可以使用 POST 参数来发送和接收数据,或者如果您想要更高的安全性,那么您可以通过安全算法加密和解密数据