我在我的Android应用程序中添加了改装2。 我拦截了我添加jwt标头的请求。 我不明白什么不与拦截器一起工作:
class ApiInterceptor implements Interceptor {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
Response response = null;
SharedPreferences preferences = MyApplication.getAppContext()
.getSharedPreferences("LWUserPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
// Do anything with request here
// set api token
// if not route api/login
if (!"/api/login".equalsIgnoreCase(request.url().encodedPath())) {
String apiToken = preferences.getString("apiToken", null);
// set authorization header
request = request.newBuilder()
.header("Authorization", "Bearer " + apiToken)
.build();
response = chain.proceed(request);
[...]
我收到此错误消息:
02-22 22:14:01.006 8588-8588/debug W/System.err: java.net.ProtocolException: Unexpected status line: array(5) {
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.StatusLine.parse(StatusLine.java:54)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.Http1xStream.readResponse(Http1xStream.java:185)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:126)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:707)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.access$200(HttpEngine.java:81)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:692)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:547)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall.getResponse(RealCall.java:242)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:199)
02-22 22:14:01.007 8588-8588/debug W/System.err: at api.ApiInterceptor.intercept(ApiClient.java:100)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:188)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:203)
02-22 22:14:01.007 8588-8588/debug W/System.err: at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:188)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:161)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall.access$100(RealCall.java:30)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
02-22 22:14:01.008 8588-8588/debug W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
02-22 22:14:01.008 8588-8588/debug W/System.err: at java.lang.Thread.run(Thread.java:818)
有什么想法吗? (使用laravel 5.2运行服务器)