2016-07-26 2 views
0
 OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).addInterceptor(new Interceptor() { 
     @Override 
     public Response intercept(Chain chain) throws IOException { 
      Request.Builder requestBuilder = chain.request().newBuilder(); 
    requestBuilder.header("Content-Type", "application/x-www-form-urlencoded"); 
    requestBuilder.header("Accept", "text/json"); 
    requestBuilder.header("Authorization","Basic fh73hf78fhhf7at");  }).build(); 

Retrofit retrofit = new Retrofit.Builder().baseUrl(BASE_URL).client(client).addConverterFactory(GsonConv erterFactory.create()).build(); 
    BetaAPI betaAPI = retrofit.create(BetaAPI.class); 

콘텐츠 유형 x-www-form-urlencoded의 원시 문자열을 추가 장착하는 방법은 무엇입니까? 개조 의 인터페이스 그래서

@POST("core/connect/userinfo") 
    Call<ResponseBody> getLogin(@Body String params); 

답변

2

는이

@FormUrlEncoded 
@POST("core/connect/userinfo") 
Call<ResponseBody> getLogin(@Field("username") String username,@Field("password") String password, @Field("scope") String scope); 
처럼 할 수 있습니다 (PARAMS는 유형, "사용자 이름 = 데이비드 & 암호 = test123 & 범위 = 오픈 ID + 이메일"입니다)

또는 사용 fieldMap 주석

@FormUrlEncoded 
@POST("core/connect/userinfo") 
Call<ResponseBody> getLogin(@FieldMap(encoded = true) Map<String, String> params); 
+0

이것은 그렇게 할 방법이 아닙니다. 위에서 언급 한 방법은 작동하지 않습니다. –

+0

공식 문서 참조 - http://square.github.io/retrofit/2.x/retrofit/ – SaravInfern

관련 문제