yy1717
2024-02-28 27fc91fbe8f88b6885356e68828cfe1ce1db7601
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.anyun.exam.lib.net
 
import android.util.Base64
import android.util.Log
import java.nio.charset.StandardCharsets
 
class NtripTcpClient(session: TcpSession) : NettyTcpClient(session) {
    companion object {
 
    }
 
    fun sendNtripRequest(clientName: String, mountPoint: String,
        username: String, password: String) {
        val request = "GET /" + mountPoint + " HTTP/1.1\r\n" + "Host: " +
                clientName + "\r\n" + "User-Agent: NTRIP " +
                clientName + "\r\n" + "Authorization: Basic " +
                encodeBase64(username + ":" + password) + "\r\n" +
                "Ntrip-Version: Ntrip/2.0\r\n" + "Connection: keep-alive\r\n\r\n"
 
        writeAndFlush(request)
    }
 
    private fun encodeBase64(value: String): String? {
        return Base64.encodeToString(value.toByteArray(StandardCharsets.UTF_8), Base64.NO_WRAP)
    }
}