简体   繁体   English

如何将数据从android应用程序(客户端)发送到python flask(后端)远程服务器

[英]How to send data from an android application (client) to a python flask (backend) remote server

First of all bear with me as I'm new to both android applications and python flask. 首先要忍受我,因为我是android应用程序和python flask的新手。

I found sample code (java) on the web, which sends json data from an android application to a php web page ( http://hmkcode.com/android-send-json-data-to-server/ ). 我在网上找到了示例代码(java),该示例代码将android程序中的json数据发送到php网页( http://hmkcode.com/android-send-json-data-to-server/ )。 What I want to do is to use this sample android code to send the data to a remote VPS server and use python flask as backend to receive and save the data . 我想做的是使用此示例android代码将数据发送到远程VPS服务器,并使用python flask作为后端来接收和保存数据。

As far as I understand the first thing that I have to replace is the php-address http://hmkcode.appspot.com/jsonservlet with my server's IP address (99.99.999.99) in the java code, 据我了解,我必须替换的第一件事是在Java代码中使用服务器IP地址(99.99.999.99)的php-address http://hmkcode.appspot.com/jsonservlet

    switch(view.getId()){
        case R.id.btnPost:
            if(!validate())
                Toast.makeText(getBaseContext(), "Enter some data!", Toast.LENGTH_LONG).show();
                // call AsynTask to perform network operation on separate thread
                //new HttpAsyncTask().execute("http://hmkcode.appspot.com/jsonservlet");
                new HttpAsyncTask().execute(99.99.999.99);
        break;
    }

Then I have to add the python flask code which will receive the data. 然后,我必须添加将接收数据的python flask代码。

Concerning flask I found the following code which might apply to my issue, https://github.com/javierchavez/Android-with-flask-backend/blob/master/Backend/wsgi.py . 关于flask我发现以下代码可能适用于我的问题: https://github.com/javierchavez/Android-with-flask-backend/blob/master/Backend/wsgi.py

Thus my questions are : 因此,我的问题是:

1st Is it correct to only replace the php-address with my VPS IP address, or do I also have to add the path to the flask file in my remote's server home directory. 1st仅将php-address替换为我的VPS IP地址是否正确,或者我还必须在远程服务器的主目录中添加flask文件的路径。

2nd what would be the actual flask code, which will receive the data from the application and save it to the remote server (as far as I understand the python flask file will be saved in the VPS's home directory) 第二个实际的flask代码是什么,它将从应用程序接收数据并将其保存到远程服务器(据我了解,python flask文件将保存在VPS的主目录中)

3rd do I also have to take into consideration the password required to access my VPS remote server when modifying the android and flask code? 第三 ,修改Android和Flask代码时,我还必须考虑访问VPS远程服务器所需的密码吗?

Thank you in advance 先感谢您

回答第一个问题,仅在烧瓶服务器的根(“ /”)路径上声明了您要执行的操作时才指定IP是正确的,否则您必须附加在@app中指定的路径.route()标记。

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

相关问题 如何将数据从Android应用程序发送到服务器? - How to send data from an Android application to a server? android应用程序如何与后端服务器同步数据? - How android application synchronize data with backend server? 如何从Android应用程序发送数据到客户端的数据库? - How to send data from android application to client's database? 从 Android 客户端向 Python 服务器发送消息 - Send message from Android Client to Python Server Android从客户端发送数据,由服务器检索并再次发送到客户端 - Android send data from client, retrieve by server and send again to client 如何将数据从Android应用程序发送到MYsql服务器? - How to send data from android application to MYsql server? 如何将数据从Android应用程序发送到Java Server(Apache tomcat)? - How to send data from Android application to Java Server(Apache tomcat)? 如何将数据从Android发送到服务器上的Java应用程序 - How to send data from android to java application on server 将数据(Client_id = 1,Staff_id = 2)从android应用发送到tomcat服务器 - Send data(Client_id=1,Staff_id=2) from android application to tomcat server 如何将数据从 Firebase 发送到 Android/iOS 应用程序和 Python - How to send data from Firebase to Android/iOS Application and Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM