gpt4 book ai didi

java - Android java http 与身份验证删除内容类型

转载 作者:太空宇宙 更新时间:2023-11-04 14:17:53 25 4
gpt4 key购买 nike

最近我正在使用 HTTPPost 处理请求,我需要使用 Content-Type: application/json 设置 header ,并且它需要基本身份验证,这是可能的方法:

答:

httpPost.setHeader("Content-type","application/json");
String authenData = String.format(Locale.getDefault(), "%s:%s", "xxx@xxx.com", "xxx");
String base64EncodedCredentials = Base64.encodeToString(authenData.getBytes(), Base64.DEFAULT);
httpPost.addHeader("Authentication", "Basic " + base64EncodedCredentials);

B:

httpPost.setHeader("Content-type","application/json");
httpPost.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials("xxx@xxxx.com", "xxxx"), "UTF-8", false));

而且,你猜怎么着?使用方法A,请求头将只剩下Authentication,是的,“Content-type”没有了

只有 B 可以完美地工作。

有人遇到过类似的问题吗?请帮帮我,谢谢:)

最佳答案

您使用的是哪个版本的httpclient?您可以升级到最新版本并重试。对我来说这像是一个错误。

java 文档说:

void addHeader(String name, String value) Adds a header to this message. The header will be appended to the end of the list.

关于java - Android java http 与身份验证删除内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27508828/

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