HttpsURLConnection无法在Android上响应

时间:2014-04-11 06:25:28

标签: android httpsurlconnection

我使用以下代码连接网址:

        URL url = new URL(URLPath);
        HttpsURLConnection HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("GET");
        connection.setUseCaches(false);
        connection.setAllowUserInteraction(true);
        connection.setInstanceFollowRedirects(true);
        connection.setRequestProperty("Accept", "*/*");

        InputStream respondsStream = connection.getInputStream();

但我在第InputStream respondsStream = connection.getInputStream();行上收到错误,如下所示:

04-11 14:16:11.445: W/System.err(26576): java.io.FileNotFoundException: URLPath
04-11 14:16:11.445: W/System.err(26576):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
04-11 14:16:11.445: W/System.err(26576):    at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:246)

但是如果我尝试在浏览器中键入URLPath,它可以响应成功 我确认网络是有效的 如何修改我的代码以避免错误?

0 个答案:

没有答案