Android HttpURLConnection 方法在 API 23 中被淘汰?

Android HttpURLConnection methods stubbed out in API 23?

我正在尝试在 Android Studio 项目中使用 HttpURLConnection,使用 API 23 作为我的编译 SDK 版本。在我打开它查看源代码之前,我一直很难排除故障。浏览一些方法,它们似乎被删除或不完整。例如,对于 HttpURLConnection.getErrorStream() 方法,我看到:

/**
 * Returns an input stream from the server in the case of an error such as
 * the requested file has not been found on the remote server. This stream
 * can be used to read the data the server will send back.
 *
 * @return the error input stream returned by the server.
 */
public InputStream getErrorStream() {
    return null;
}

还有其他几个方法示例似乎没有按预期执行。这是对某处记录的 API 的更改吗?我是在吃疯狂的药吗?

如有任何帮助,我们将不胜感激。

代替Ctrl-B,使用Ctrl-Alt-B,然后从sun.net.www.protocol.http中选择HttpUrlConnection(如下截图),你会发现它的详细实现:

public InputStream getErrorStream() {
        if(this.connected && this.responseCode >= 400) {
            if(this.errorStream != null) {
                return this.errorStream;
            }

        if(this.inputStream != null) {
            return this.inputStream;
        }
    }

    return null;
}