我在我的android项目中使用Retrofit 2和Okhttp.我想在api请求中添加多个标头.
public class NetworkInterceptors implements Interceptor {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request().newBuilder()
.addHeader("Userid","10034")
.addHeader("Securitykey","Fb47Gi")
.build();
return chain.proceed(request);
}
}
这不能正常工作.在服务器端,我只获得最后添加的标题(在上面的例子中我只得到Securitykey缺少“Userid”)
请帮忙.
最佳答案
感谢你的支持
我找到了答案,这对我来说很好
原文链接:https://www.f2er.com/android/429952.html我找到了答案,这对我来说很好
public class NetworkInterceptors implements Interceptor {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder()
.addHeader("Userid","10034")
.addHeader("Securitykey","Fb47Gi")
.build();
return chain.proceed(newRequest);
}
}