我试图通过使用拦截器在Android中的Retrofit 2.0-beta3和OkHttpClient添加基于令牌的身份验证.但是当我在OkHttpClient中添加拦截器时,我得到UnsupportedOperationException.这是我的代码:在ApiClient.java中
public static TrequantApiInterface getClient(final String token) {
if( sTreqantApiInterface == null) {
Log.v(RETROFIT_LOG, "Creating api client for the first time");
OkHttpClient okClient = new OkHttpClient();
okClient.interceptors().add(new Interceptor() {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
// Request customization: add request headers
Request.Builder requestBuilder = original.newBuilder()
.header("Authorization", token)
.method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
});
Retrofit client = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(okClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
sTreqantApiInterface = client.create(TrequantApiInterface.class);
}
return sTreqantApiInterface;
} …Run Code Online (Sandbox Code Playgroud) 我正在运行 Django、uwsgi、ngix 服务器。我的服务器适用于较小尺寸的 GET、POST 请求。但是在POST大尺寸的请求时,nginx返回502:nginx error.log是:
2016/03/01 13:52:19 [error] 29837#0: *1482 sendfile() failed (32: Broken pipe) while sending request to upstream, client: 175.110.112.36, server: server-ip, request: "POST /me/amptemp/ HTTP/1.1", upstream: "uwsgi://unix:///tmp/uwsgi.sock:", host: "servername"
Run Code Online (Sandbox Code Playgroud)
因此,为了找到真正的问题所在,我在不同的端口上运行 uwsgi 并检查同一请求是否发生任何错误。但是请求成功了。因此,问题出在 nginx 或 unix 套接字配置上。Ngin-x 配置:
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/uwsgi.sock; # for a file socket
# server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server …Run Code Online (Sandbox Code Playgroud)