2016-07-16 4 views
2

내가 내 API 인터페이스의 요청이 "일반 텍스트 통신은 지원되지 않습니다"HTTP 요청을 얻을 오류

@FormUrlEncoded 
@POST(ApiStatics.authorizeURL) 
Call<Oauth2Model> authorizer(@Field("grant_type") String grantType, 
          @Field("username") String userName, 
          @Field("password") String password, 
          @Field("client_id") String clientID, 
          @Field("client_secret") String clientSecret); 

오순절을이 getApi 방법 : 내 조각이 API를 사용

public static MyAPI getApi() { 
    if (api == null) { 
     OkHttpClient client; 
     if (GuildsApp.isDebug()) { 
      HttpLoggingInterceptor bodyInterceptor = new HttpLoggingInterceptor(); 
      bodyInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 
      HttpLoggingInterceptor headerInterceptor = new HttpLoggingInterceptor(); 
      headerInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); 
      client = new OkHttpClient.Builder().readTimeout(5, TimeUnit.MINUTES).writeTimeout(5, TimeUnit.MINUTES).connectTimeout(5, TimeUnit.MINUTES).addInterceptor(bodyInterceptor).addInterceptor(headerInterceptor).build(); 
     } else { 
      client = new OkHttpClient.Builder().readTimeout(5, TimeUnit.MINUTES).writeTimeout(5, TimeUnit.MINUTES).connectTimeout(5, TimeUnit.MINUTES).build(); 
     } 
     Retrofit.Builder builder = new Retrofit.Builder(); 
     builder.baseUrl(BASE_URL); 
     builder.addConverterFactory(GsonConverterFactory.create()); 
     builder.client(client); 
     Retrofit retrofit = builder.build(); 
     api = retrofit.create(MyAPI.class); 
    } 
    return api; 
} 

private void login(String user, String pass) { 
    ApiManager.getApi().authorizer("password", user, pass, ApiStatics.CID,ApiStatics.CSecret).enqueue(new Callback<Oauth2Model>() { 
     @Override 
     public void onResponse(Call<Oauth2Model> call, Response<Oauth2Model> response) { 
      Log.e("authorize token",""+response.body().access_token); 
     } 

     @Override 
     public void onFailure(Call<Oauth2Model> call, Throwable t) { 
      Log.e("Failure ",""+t.getLocalizedMessage()); 
     } 
    }); 
} 

내가이 로그인과 프로젝트, 요청 전화 onFailure 방법을 실행할 때 :

이 방법

E/실패 : 평문 통신을 지원하지 : 연 a (암호화 방식 = TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_3DES_EDE_CBC_SHA] tlsVersions = TLS_1_2, TLS_1_1, TLS_1_0] supportsTlsExtensions = TRUE), 후 연 (암호화 방식 = TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES _128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_3DES_EDE_CBC_SHA, tlsVersions = [TLS_1_0, supportsTlsExtensions = TRUE)]

내 BASE_URL은 HTTP가 아닌 HTTPS입니다. login ("", "");으로 로그인 정보가 호출되었습니다. 그 ""는 서버에서 허용됩니다. 어떻게이 오류를 해결할 수 있습니까? Retrofit 2.1.0을 사용합니다. 내 테스트 장치는 ApiManager가 아닌 내 조각 안에 간단한 getApi 메소드를 추가하여 nexus 5x android N

답변

1

입니다.

private MyAPI getApi(){ 
    Retrofit.Builder builder = new Retrofit.Builder(); 
    builder.baseUrl(ApiManager.BASE_URL); 
    builder.addConverterFactory(GsonConverterFactory.create()); 
    Retrofit retrofit = builder.build(); 
    return retrofit.create(MyAPI.class); 
} 

내 로그인 방법은 지금 :

private void login(String user, String pass) { 
getApi().authorizer("password", user, pass, ApiStatics.CID,ApiStatics.CSecret).enqueue(new Callback<Oauth2Model>() { 
    @Override 
    public void onResponse(Call<Oauth2Model> call, Response<Oauth2Model> response) { 
     Log.e("authorize token",""+response.body().access_token); 
    } 

    @Override 
    public void onFailure(Call<Oauth2Model> call, Throwable t) { 
     Log.e("Failure ",""+t.getLocalizedMessage()); 
    } 
}); 
} 

어떤 몸은 내 ApiManager에 내 조각에 getApi 방법을 구현의 차이가 무엇인지 나에게 설명 할 수 있습니까?

2

이 주석을 클래스 맨 위에 추가하십시오.

@PowerMockIgnore("javax.net.ssl.*") 

SSL 검사를 무시합니다.