小编Coi*_*ter的帖子

使用requestInterceptor改进基本身份验证

我一直在尝试使用基本身份验证来使用改造和requestInterceptor,但我一直拒绝连接.我从https://github.com/square/retrofit的改造示例开始. 我开始使用的链接到文件:https://github.com/square/retrofit/blob/master/retrofit-samples/github-client/src /main/java/com/example/retrofit/GitHubClient.java

import java.util.List;

import javax.xml.bind.DatatypeConverter;

import retrofit.RequestInterceptor;
import retrofit.RestAdapter;
import retrofit.client.OkClient;

public class Client {
    private static final String API_URL = "https://localhost:3000/v1";
    private static RestAdapter restAdapter = null;

    public RestAdapter getAdapter() {
        return restAdapter;
    }

    public static void init(final String username, final String password) {
        OkHttpClient okHttpClient = new OkHttpClient();

        RequestInterceptor requestInterceptor = new RequestInterceptor() {
            @Override
            public void intercept(RequestFacade request) {
                request.addHeader("Authorization", "Basic NTMzYWM5MmYxZTIxYmMwMDAwZWJlNTBlOmQ=");
                //getToken(username, password)
            }
        };

        restAdapter = new RestAdapter.Builder() …
Run Code Online (Sandbox Code Playgroud)

java basic-authentication retrofit

5
推荐指数
1
解决办法
3192
查看次数

标签 统计

basic-authentication ×1

java ×1

retrofit ×1