让android studio从web获取数据并添加到url

I own a live tv app on android, but it was only made to play normal streams. However, my streams have token authentication in order to play so the stream must get the token from my server and add it to the end of the url then play. How can I do this on android studio? I basically am trying to get the app to get the token from my webpage where it is generated and add it to the end of the stream url then play.

I would appreciate it if someone could point me in the right direction. Thanks in advance.

To do that you need to provide your access-token from a wen service, thene add the token to the end of the url, thene usethe new URL.

here an eample of a code (PHP) that generates a random access token thene provide it in the address " path-to-script/gettoken.php "

<?php
     // the content of gettoken.php

    // a funtion to generate random strings : they will serve as your tokens 
        function generateRandomString($length = 10) {
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $charactersLength = strlen($characters);
            $randomString = '';
            for ($i = 0; $i < $length; $i++) {
                $randomString .= $characters[rand(0, $charactersLength - 1)];
            }
            return $randomString;
        }

// thene we will send the tokenwhee we recieve a GETrequestin the url of the script.
 echo generateRandomString(10)
?>

In the Java Code you will get the token by the following lines of code :

// a function to send a get request 
public String sendGetRequest(String requestURL) {
        StringBuilder sb = new StringBuilder();
        try {
            URL url = new URL(requestURL);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));

            String s;
            while ((s = bufferedReader.readLine()) != null) {
                sb.append(s + "
");
            }
        } catch (Exception e) {
        }
        return sb.toString();
    }

// gettig a token
String URL = "The url of the php script" // replace itwithe  correct URL
String token=sendGetRequest(URL)

By this you will be able to retrieve the token in your android app thene useitin the code.