简体   繁体   中英

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.

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/ ). 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 .

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,

    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.

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 .

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.

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)

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?

Thank you in advance

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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