gpt4 book ai didi

java - Android HttpURLConnection 方法在 API 23 中被删除?

转载 作者:行者123 更新时间:2023-12-02 04:23:21 25 4
gpt4 key购买 nike

我正在尝试使用HttpURLConnection在使用 API 23 作为我的编译 SDK 版本的 Android Studio 项目中。在我打开它查看源代码之前,我一直很难排除故障。浏览一些方法,它们似乎被删除或不完整。作为一个例子,对于方法 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-Alt-B 而不是 Ctrl-B,然后从 sun.net.www 选择 HttpUrlConnection .protocol.http(如下截图),你会发现它的详细实现:

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;
}

Implementation of getErrorStream

关于java - Android HttpURLConnection 方法在 API 23 中被删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32493905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com