Ver código fonte

定义请求的路径

xiongweixp 2 meses atrás
pai
commit
8f657c315e

+ 5 - 2
app/src/main/java/tech/xiongweixp/touchaction/MainActivity.kt

@@ -28,13 +28,16 @@ class MainActivity : ComponentActivity() {
     private fun hassioRequest(webhookID: String) {
         Thread {
             try {
-                var url = URL("URL_ADDRESS")
-                var conn = url.openConnection() as HttpURLConnection
+                val url = URL("http://192.168.31.45:8123/api/webhook/$webhookID")
+                val conn = url.openConnection() as HttpURLConnection
                 conn.requestMethod = "GET"
                 conn.doInput = true
                 conn.doOutput = false
                 Log.i("MainActivity", "发送get请求:$webhookID" )
                 conn.connect()
+                val ret = conn.responseCode
+                Log.i("MainActivity", "发送 $webhookID 请求成功,返回码:$ret")
+                conn.disconnect()
             }
             catch (e: Exception) {
                 Log.i("MainActivity", "发送 $webhookID 请求失败")