有 getHeaderFields()但这会返回响应 HTTP 消息中的 header 。我想要请求消息中的 header ,而不是响应。
另外,Properties 和 Headers 有什么区别?好像setRequestProperty()正在设置标题,但我不确定。
最佳答案
如果您检查 getRequestProperties() 方法,您会发现您的猜测是正确的:
public Map<String,List<String>> getRequestProperties()
Returns an unmodifiable Map of general request properties for this connection. The Map keys are Strings that represent the request-header field names. Each Map value is a unmodifiable List of Strings that represents the corresponding field values.
关于java - 如何查看默认 JDK HttpURLConnection 的 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23931055/