简体   繁体   English

从Android应用程序向Web托管的Java应用程序发送和接收数据

[英]Sending and receiving data from an Android application to a web hosted Java application

I've been looking around all morning, and can't seem to figure this one out. 我整个上午一直在四处张望,似乎无法弄清楚这一点。 I know it's not as complicated as I think it is, and all I need is just some pointers to the right direction. 我知道它并没有我想的那么复杂,我所需要的只是指向正确方向的一些指针。

I have an Android application that takes some user input, sends it to a Java application over the web, and then receives some output based on the input. 我有一个Android应用程序,它需要一些用户输入,然后通过网络将其发送到Java应用程序,然后根据输入接收一些输出。

My Android and Java applications are ready, but how do I go about sending and receiving the data over the web? 我的Android和Java应用程序已准备就绪,但是如何通过网络发送和接收数据呢? I understand that I'll be sending and receiving HTTP requests, but my problem is where I'll be sending them and receiving them from. 我知道我将发送和接收HTTP请求,但是我的问题是如何发送和接收HTTP请求。 Do I host my Java application on a Servlet like Tomcat, or do I use something like OpenShift to host my application for me? 我是将Java应用程序托管在Tomcat之类的Servlet上,还是使用OpenShift之类的功能来为我托管应用程序?

I have no trouble with sending some HTTP request from my Android application to the web and receiving some output back, but my problem is that my web service needs to use a Java library to process the input and generate the output. 我从Android应用程序向网络发送一些HTTP请求并收到一些输出没有问题,但是我的问题是我的Web服务需要使用Java库来处理输入并生成输出。 I'm just not sure how I'm supposed to get this data to and from this Java library that needs to be hosted on the web. 我只是不确定应该如何从需要托管在Web上的Java库中获取数据。

I hope my question makes any sense. 我希望我的问题有任何道理。

EDIT: Perhaps I wasn't clear with what exactly I need help with. 编辑:也许我不清楚我到底需要什么帮助。 I do realize that the architecture I use doesn't really make any difference, but the problem I have is with how I'm supposed to use this architecture. 我的确意识到我使用的体系结构并没有什么区别,但是我遇到的问题是如何使用该体系结构。

Let's say I have a registered domain name that I can easily send to and receive data from using my Android application - no trouble with that. 假设我有一个注册的域名,可以轻松地使用我的Android应用程序发送和接收数据-这样做没有问题。 But how am I supposed to integrate my Java library with this server? 但是我应该如何将Java库与此服务器集成? Do I just create an applet and put it on my server? 我是否只是创建一个applet并将其放在服务器上? Does my web host even allow Java applets to run? 我的虚拟主机甚至允许Java小程序运行吗?

I guess my question is how I'm supposed to get through the "barrier" between my HTTP request / transport layer protocol and my Java application. 我想我的问题是我应该如何穿越HTTP请求/传输层协议与Java应用程序之间的“障碍”。

Server architecture usually does not matter. 服务器体系结构通常无关紧要。 You can use Java, NodeJs, Rails, Python, .NET, etc. You just need an endpoint that accepts a HTTP POST/PUT/GET/DELETE/PATCH verb. 您可以使用Java,NodeJ,Rails,Python,.NET等。您只需要一个接受HTTP POST / PUT / GET / DELETE / PATCH动词的端点即可。

This is more a question of "how do I set up a server to accept input" and its a very large topic in itself. 这更多是一个问题:“我如何设置服务器以接受输入”,这本身就是一个很大的话题。 I would advise you look at PAAS solutions like: 我建议您看一下PAAS解决方案,例如:

You can use their tools to build a solution fairly quickly. 您可以使用他们的工具来快速构建解决方案。 If you need something custom you'll need to build your backend in the language of choice and host it online via AWS, Google Cloud, Heroku, a VPS or something similar. 如果您需要自定义内容,则需要以所选语言构建后端,并通过AWS,Google Cloud,Heroku,VPS或类似方式在线托管它。

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

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