I made a webserver in asp.net with some API. The server run with IIS in localhost, and i have to connect to it from my Android app (using the android studio emulator). The problem is that i can't connect to the webserver. I tried with ngrok and when i make a request I get
Bad Request - Invalid Hostname
HTTP Error 400. The request hostname is invalid.
I also tried Conveyor but when i make a request I get
I/System.out: Volley error: com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Can someone help me please? I have no idea how to solve this.. all the tutorials and questions say the same things and not work for me.
Here the code of kotlin request:
// i don't put the correct url in the question for security
val url = "https://255.255.255.255:44307/api/login"
// Post parameters
// Form fields and values
val params = HashMap<String,String>()
params["mail"] = email.text.toString()
params["pw"] = password.text.toString()
val jsonObject = JSONObject(params as Map<*, *>)
// Volley post request with parameters
val request = JsonObjectRequest(
Request.Method.POST, url, jsonObject,
{ response ->
// Process the json
try {
println( "Response:$response")
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
//textView.text = "Response: $response"
} catch (e: Exception) {
println( "Response:$response")
//textView.text = "Exception: $e"
}
}, {
// Error in request
println("Volley error: $it")
//textView.text = "Volley error: $it"
})
// Volley request policy, only one time request to avoid duplicate transaction
request.retryPolicy = DefaultRetryPolicy(
DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
// 0 means no retry
0, // DefaultRetryPolicy.DEFAULT_MAX_RETRIES = 2
1f // DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
)
// Add the volley post request to the request queue
VolleySingleton.getInstance(this).addToRequestQueue(request)
// Add the volley post request to the request queue
VolleySingleton.getInstance(this).addToRequestQueue(request)