I have the following POST request that's written by using Java 11's HttpClient. But Android Studio does not recognize the libraries.
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 the JDK path is set to my default JDK C:\Program Files\Java\jdk-11.0.8 also in modules:
What am i doing wrong? What can i do to implement a Http method with Java 11 HttpClient?

java.net.http.HttpClientare simply not available on Android (see availablejava.netclasses). The only chance would be to extract the necessary classes from JRE and add them to your project as library.