【发布时间】:2019-11-04 17:24:24
【问题描述】:
我一直在将 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 runnign,它没有收到任何东西。仅供参考,我正在使用 Kotlin 中的 Volley 在该网址上发出发布请求,这是我的代码:
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)
【问题讨论】:
-
您尝试的 URL
http://1z5d90b4.ngrok.io/api/v1/users/id/看起来不正确。可能是..但奇怪的是没有最终的 URL 参数,例如用户 ID ? -
其实我剪掉了url,只是觉得没必要。但它是这样的:
http://1z5d90b4.ngrok.io/api/v1/users/A328dJDFj39dj34L/status当我使用 Postman 发出请求时它会起作用 -
您的 URL 是 http 但错误与 SSL 相关,这似乎很奇怪...?
-
@CodyCaughlan 感谢您抽出时间检查代码并做出响应。我发现了问题!那是网络防火墙!我只是没想到这一点,因为在工作中我们有一个客人和一个工作网络。我的假设是,由于工作网络更安全,如果工作网络上运行良好,它也可以在访客网络上运行!!但是,ngrok 在访客网络上被阻止,这是唯一的问题。
标签: android kotlin httprequest android-volley ngrok