我一直在为许多项目使用ngrok,主要是语音应用程序和rest api。我只需要在Android应用程序中使用我的rest api。但是,无论我做什么,出于某些原因都无法正常工作!
如果我尝试使用http,将会得到以下错误:
E/Volley: [17118] BasicNetwork.performRequest: Unexpected response code 307 for http://1z5d90b4.ngrok.io/api/v1/users/id/
I/System.out: That didn't work! com.android.volley.ServerError
如果我尝试使用https链接,得到的结果如下:
com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0xd7821100: I/O error during system call, Connection reset by peer
我不知道发生了什么!我检查了在我的电脑上运行的ngrok,但是它没有接收到任何信息。提供信息,我正在使用Kotlin中的Volley在该URL上进行post请求,这是我的代码:
val queue = Volley.newRequestQueue(this)
// Request a string response from the provided URL.
val stringRequest = JsonObjectRequest(Request.Method.POST, apiUrl, params,
Response.Listener { response ->
// Display the first 500 characters of the response string.
println("Response is: $response")
},
Response.ErrorListener { error -> println("That didn't work! ${error}") })
queue.add(stringRequest)
http://1z5d90b4.ngrok.io/api/v1/users/id/
看起来不正确。它可能是正确的,但奇怪的是没有最终的URL参数,例如用户ID? - Cody Caughlan当我使用Postman发出请求时,它可以正常工作。 - Mark