Retrofit为每个自定义标头添加前缀“HTTP_”

问题描述 投票:0回答:1

我不知道为什么Retrofit在我尝试添加的每个自定义标头之前添加“HTTP_”。

public interface UserService {

    @POST("api/users/details/bio/update/")
    Call<User> updateBio(@Header("Authorization") String text,@Body User user);

}

当我执行此代码时,在我的服务器上它显示标题为“HTTP_AUTHORIZATION”。

以下是将请求发送到服务器时的日志

12-29 07:41:46.528 3207-3207/com.application.university V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@cd0612c
12-29 07:41:46.528 3207-3207/com.application.university V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@65cf7f5
12-29 07:41:46.543 3207-3207/com.application.university V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@312bfb
12-29 07:41:46.544 3207-3207/com.application.university V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@f786418
12-29 07:41:46.638 3207-3212/com.application.university I/art: Do partial code cache collection, code=457KB, data=386KB
12-29 07:41:46.639 3207-3212/com.application.university I/art: After code cache collection, code=457KB, data=386KB
12-29 07:41:46.639 3207-3212/com.application.university I/art: Increasing code cache capacity to 2MB
12-29 07:41:46.639 3207-3212/com.application.university I/art: Compiler allocated 7MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
12-29 07:41:47.055 3207-3207/com.application.university I/Toast: Show toast from OpPackageName:com.application.university, PackageName:com.application.university

                                                                 --------- beginning of system

我也尝试过Interceptor类。它仍然没有任何差异。

public class AuthenticationInterceptor implements Interceptor {
    private String authToken;

    public AuthenticationInterceptor(String token) {
        this.authToken = token;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request original = chain.request();

        Request.Builder builder = original.newBuilder().header("Authorization", authToken);

        Request request = builder.build();
        return chain.proceed(request);
    }
}
android api http retrofit okhttp
1个回答
0
投票

它不是客户。您使用CGI作为服务器还是类似的东西? IIRC这就是标头转向的方式。

https://tools.ietf.org/html/rfc3875#section-4.1.18

How do I access the HTTP Header of request in a CGI script?

© www.soinside.com 2019 - 2024. All rights reserved.