2017-03-10 60 views
0

這是我的網址http://192.168.1.217:8088/api/frontend/web/index.php?r=api/sms/send,我需要採取一些參數,可以以下是PARAM如何使用Retrofit從服務器發送郵件請求?

{"body":{"param":"VjvBNGoYQ3/nCytxN0zx5rr+6sewp7FABok5N3DdDdD0WWu7KCCohA=="}, 
"header":{"deviceId":"","appToken":"","serviceCode":"sms","appType":1,"appVersion":1,"clientType":1}} 

我768,16如何編寫代碼使用改裝?謝謝提前。

回答

0

這是我關於如何使用改裝到目前爲止http://www.androidhive.info/2016/05/android-working-with-retrofit-http-library/ 找到了最好的榜樣,但是,如果你想另一個例子是在這裏我用OpenWeatherMap的代碼。

public class ApiClient { 
    private static final int TIME_OUT = 30; 
    public static final String BASE_URL = "http://api.openweathermap.org/"; 
    private static Retrofit retrofit = null; 


    public static Retrofit getClient() { 
     if (retrofit==null) { 
      OkHttpClient.Builder okBuilder = new OkHttpClient.Builder(); 

      okBuilder.connectTimeout(TIME_OUT, TimeUnit.SECONDS); 
      okBuilder.readTimeout(TIME_OUT, TimeUnit.SECONDS); 
      okBuilder.writeTimeout(TIME_OUT, TimeUnit.SECONDS); 

      Gson gson = new GsonBuilder().create(); 

      return new Retrofit.Builder() 
       .baseUrl(BASE_URL)     .addConverterFactory(ScalarsConverterFactory.create()) 
       .addConverterFactory(GsonConverterFactory.create(gson)) 
       .client(okBuilder.build()) 
       .build(); 
    } 
    return retrofit; 
} 

public interface ApiInterface { 
    @GET("data/2.5/forecast?id=524901") 
    Call<WeatherResponse> getWeatherData(@Query("APPID") String apiKey); 
} 
+0

謝謝,讓我看看,我不知道如何定義BaseUrl? –

相關問題