James Black
04/18/2022, 4:26 AMcurl -X POST -d 'Hello' <http://0.0.0.0:8080/outfit_data>
success%
The error I get from android is:
I/System.out: Failed to connect to /0.0.0.0:8080 calling <http://0.0.0.0:8080/outfit_data>
This is my ktor 2.0.0 routing:
post("/outfit_data") {
val data = call.receive<String>()
println(data)
call.respondText("success", null, HttpStatusCode.OK)
}
And on the android side this is how I make the call, and baseUrl is set as this is the top-level gradle.properties file
weather_client_host_name=<http://0.0.0.0:8080>
try {
<http://client.post|client.post>(
"$baseUrl/outfit_data"
) {
contentType(ContentType.Application.Json)
setBody(data)
}.also { response ->
return response.status == HttpStatusCode.OK || response.status == HttpStatusCode.Created
}
} catch(e:Throwable) {
println("${e.message} calling $baseUrl/outfit_data")
return false
}
My code is in the androidApp, shared/androidMain and server subprojects. The http call for Android is in shared/src/androidMain/.../api/WeatherApi.kt
I also put this in the android manifest in the shared/src/androidMain:
<application
android:usesCleartextTraffic="true">
https://github.com/jblack975/MyOutfitPicker/tree/pass_anon_data_to_serverAndrey Tabakov
04/18/2022, 4:30 AMAleksei Tirman [JB]
04/18/2022, 8:26 AMChrimaeon
04/18/2022, 12:08 PM10.0.2.2.
see here https://developer.android.com/studio/run/emulator-networkingChrimaeon
04/18/2022, 12:09 PMJames Black
04/18/2022, 11:07 PM