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

So in der Schnittstelle von Retrofit (params ist von der Art, "username = david & password = test123 & scope = openid + E-Mail")Wie übergebe ich rohe Zeichenkette des Inhaltstyps x-www-form-urlencoded in Retrofit?

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

Antwort

2

Sie so

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

oder verwenden FieldMap Anmerkung

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

Dies ist nicht der richtige Weg. Die oben genannte Methode funktioniert nicht. –

+0

können Sie die offizielle Dokumentation beziehen - http://square.github.io/retrofit/2.x/retrofit/ – SaravInfern