我有一些问题。当我发送 get-request(来自 android 应用程序和浏览器)时,我的服务器响应我 403 错误。我做错了什么?
trustAllHosts();
urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setHostnameVerifier(DO_NOT_VERIFY);
urlConnection.setReadTimeout(CONNECT_TIMEOUT);
urlConnection.setConnectTimeout(CONNECT_TIMEOUT / 2);
//urlConnection.connect();
int respCode = urlConnection.getResponseCode();
if (respCode >= 400) {
if (respCode == 404 || respCode == 410) {
throw new FileNotFoundException(url.toString());
} else {
throw new java.io.IOException(
"Server returned HTTP"
+ " response code: " + respCode
+ " for URL: " + url.toString());
}
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream()), 1000);
方法 trustAllHosts() 需要 SSL 选项。
谢谢你。最好的问候,pp