我查看了 android studio 中 URLConnection.setRequestProperty 的源代码,它似乎没有设置任何内容:
public void setRequestProperty(String field, String newValue) {
checkNotConnected();
if (field == null) {
throw new NullPointerException("field == null");
}
}
这是 checkNotConnected():
private void checkNotConnected() {
if (connected) {
throw new IllegalStateException("Already connected");
}
}
我在这里缺少什么?因为这个方法似乎什么也没做。
最佳答案
URLConnection 是一个抽象类,可以被扩展类覆盖。当您重写该方法时,您应该在执行您自己的代码之前调用 super()。使用上面的代码,它将在执行重写类的代码之前检查基本异常。
关于Android Studio中的Java URLConnection.setRequestProperty似乎没有做任何事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36453714/