我在编写我的第一个Android应用程序时遇到了一个问题。
我想围绕我现有的want服务器/want界面建立应用程序的登录系统。
我正在使用Fuel-Library,据我所知,GET请求工作正常。问题在于回应。当我将其打印出来时,所看到的一切都是关于请求本身的一些信息,但是来自PHP的打印回显并没有出现在任何地方。
打印出的响应:
I/System.out: <-- 200 https://...hidden :)
I/System.out: Response : OK
Length : -1
Body : test
Headers : (11)
Connection : Keep-Alive
Date : Mon, 30 Mar 2020 18:06:39 GMT
X-Android-Selected-Protocol : http/1.1
Server : Apache
X-Powered-By : PHP/7.3.5, PleskLin
Content-Type : text/html; charset=UTF-8
X-Android-Received-Millis : 1585591597000
Vary : Accept-Encoding
X-Android-Response-Source : NETWORK 200
X-Android-Sent-Millis : 1585591596960
Keep-Alive : timeout=5, max=100POST请求也是如此。
这是我的Kotlin代码:
val url = "https://myserver.com/testlogin.php?username=".plus(username.toString()).plus("&password=").plus(password.toString())
url.httpGet().responseString{
request, response, result ->
Toast.makeText(this@MainActivity, result.toString(), Toast.LENGTH_LONG).show()
}和And服务器上的PHP代码:
<?php $username = $_GET["username"]; $password = $_GET["password"]; echo $username; ?>我已经找了7个多小时了。发送帮助
发布于 2020-03-31 02:58:53
尝尝这个
url.httpGet().responseString { request, response, result ->
when (result) {
is Result.Failure -> {
val ex = result.getException()
println(ex)
}
is Result.Success -> {
val data = result.get()
println(data)
}
}
}发布于 2020-03-31 02:54:25
我发现了问题所在:
val data = result.get() println(data)打印php文件的响应字符串。
https://stackoverflow.com/questions/60936822
复制相似问题