2016-07-26 1 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); 

donc dans l'interface de mise à niveau (params est du type "nom d'utilisateur = david & password = test123 & scope = Openid + email")Comment passer la chaîne brute du type de contenu x-www-form-urlencoded en retrofit?

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

Répondre

2

vous pouvez faire comme ce

@FormUrlEncoded 
@POST("core/connect/userinfo") 
Call<ResponseBody> getLogin(@Field("username") String username,@Field("password") String password, @Field("scope") String scope); 

ou utiliser l'annotation FieldMap

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

Ce n'est pas la façon de le faire. La méthode mentionnée ci-dessus ne fonctionne pas. –

+0

vous pouvez vous référer à la documentation officielle - http://square.github.io/retrofit/2.x/retrofit/ – SaravInfern