gpt4 book ai didi

java - HttpClient setHeader 和 addHeader 有什么区别?

转载 作者:行者123 更新时间:2023-12-01 06:34:17 24 4
gpt4 key购买 nike

使用 Apache HttpClient 版本时:

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>

setHeader 和 addHeader 有什么区别?

    httpPost.addHeader("AuthenticationKey",authenticationKey);
httpPost.addHeader("Content-Type","application/json");

httpPost.setHeader("Cache-Control", "no-cache"); // HTTP 1.1
httpPost.setHeader("Pragma", "no-cache"); // HTTP 1.0
httpPost.setHeader("X-Requested-With", "XMLHttpRequest"); // mimics a browser REST request

最佳答案

正如您可以从文档中读到的:

addHeader(String name, String value

Adds a header to this message. The header will be appended to the end of the list.

setHeader(String name, String value

Overwrites the first header with the same name. The new header will be appended to the end of the list, if no header with the given name can be found.

关于java - HttpClient setHeader 和 addHeader 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53071229/

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