服务器出现403(禁止)错误

时间:2014-06-25 13:49:24

标签: java android http httpsurlconnection

我有一些问题。 当我发送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。

0 个答案:

没有答案