hul*_*ist 2 android httpurlconnection xamarin
所以基本上现在我的应用程序配置为使用 https,因为在“版本”中它将使用自签名证书,并且显然也使用 https。
我当前的测试系统(还有一些功能)不使用 https,而是使用 http。我认为最好有某种类型的方法来检查给定的 URL 是 Http 还是 Https,并根据结果创建正确的 URLConnection。
我当前的问题是我不知道该方法到底应该是什么样子。我考虑过在连接到我的服务器的方法中使用 if 语句,但可能有更好的解决方案。
如有帮助,将不胜感激。
这个怎么样:
URLUtil.isHttpUrl(String url)
URLUtil.isHttpsUrl(String url)
Run Code Online (Sandbox Code Playgroud)
另请参阅:http ://developer.android.com/reference/android/webkit/URLUtil.html
如果您不想进行手动检查,您可以使用像这样的第三方库: http: //square.github.io/okhttp/,它可以让您简单地:
Request request = new Request.Builder().url(url).build();
Response response = new OkHttpClient().newCall(request).execute();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1261 次 |
| 最近记录: |