亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

getHeaderField為何總是return null

getHeaderField為何總是return null

MM們 2018-08-10 18:41:17
各位大佬,我無意中查看源碼的時候產生如下疑問:java.net.URLConnection類中有一個getHeaderFieldDate方法,如下:@SuppressWarnings("deprecation")public long getHeaderFieldDate(String name, long Default) {     String value = getHeaderField(name);    try {        return Date.parse(value);     } catch (Exception e) { }    return Default; }該方法中調用了一個getHeaderField方法,如下:public String getHeaderField(String name) {    return null; }getHeaderField方法總是返回null,這是為什么呢?謝謝!
查看完整描述

1 回答

?
慕后森

TA貢獻1802條經驗 獲得超5個贊

    /**
     * Returns the value of the named header field.
     * <p>
     * If called on a connection that sets the same header multiple times
     * with possibly different values, only the last value is returned.
     *
     *
     * @param   name   the name of a header field.
     * @return  the value of the named header field, or {@code null}
     *          if there is no such field in the header.
     */
    public String getHeaderField(String name) {        return null;
    }

事實上這個方法在常見實現類里都有被覆寫:

https://img1.sycdn.imooc.com//5b700cfa0001e51a08000176.jpg

比如常見的 HttpURLConnection 中:

public String getHeaderField(String var1) {    try {        this.getInputStream();
    } catch (IOException var3) {
        ;
    }    return this.cachedHeaders != null 
        ? this.filterHeaderField(var1, this.cachedHeaders.findValue(var1)) 
        : this.filterHeaderField(var1, this.responses.findValue(var1));
}


查看完整回答
反對 回復 2018-08-12
  • 1 回答
  • 0 關注
  • 1388 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號