我有一些问题。 当我发送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选项。
谢谢。最佳标志,p.p。