改造是前缀" HTTP _"到每个自定义标题

时间:2017-12-28 17:25:06

标签: android api http retrofit okhttp

我不知道为什么Retrofit正在添加" HTTP _"在我尝试添加的每个自定义标题之前。

public interface UserService {

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

}

当我执行此代码时,在我的服务器上显示标题为&#34; HTTP_AUTHORIZATION&#34;。

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

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);
    }
}

1 个答案:

答案 0 :(得分: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?