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)
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I solve the problem removing the ssl from the server and using the tip of @Michal
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0