我有以下使用 Java 11 的 HttpClient 编写的 POST 请求。但 Android Studio 无法识别这些库。
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
class Verification {
fun verify(username: String, signature: String) {
try {
HttpClient.newHttpClient().send(HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofString("$username:$signature"))
.uri(URI.create("http://localhost:9080/sse/verify"))
.build(), HttpResponse.BodyHandlers.ofString())
} catch (e: Exception) {
e.printStackTrace()
}
}
}
build.gradle:
android {
compileSdkVersion 29
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "io.example.code"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
And in Android Studio Project Structure
JDK路径设置为我的默认JDKC:\Program Files\Java\jdk-11.0.8
也在模块中:
我究竟做错了什么?我可以做什么来使用 Java 11 HttpClient 实现 Http 方法?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)