【问题标题】:Retrofit is prefixing "HTTP_" to every custom header改造为每个自定义标头添加“HTTP_”前缀
【发布时间】:2017-12-28 17:25:06
【问题描述】:

我不知道为什么 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】:

不是客户端。您是否使用 CGI 作为您的服务器或类似的东西? IIRC 这就是标题的转变方式。

https://www.rfc-editor.org/rfc/rfc3875#section-4.1.18

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 2014-12-23
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多