1
Retrofit 2 ลบอักขระหลังชื่อโฮสต์ออกจาก URL พื้นฐาน
ฉันใช้ Retrofit เพื่อเข้าถึง RESTful api URL ฐานคือ: http://api.example.com/service นี่คือรหัสสำหรับอินเทอร์เฟซ: public interface ExampleService { @Headers("Accept: Application/JSON") @POST("/album/featured-albums") Call<List<Album>> listFeaturedAlbums(); } และนี่คือวิธีที่ฉันส่งคำขอและรับการตอบกลับ: new AsyncTask<Void, Void, Response<List<Album>>>() { @Override protected Response<List<Album>> doInBackground(Void... params) { Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://api.example.com/service") .addConverterFactory(GsonConverterFactory.create()) .build(); ExampleService service = retrofit.create(ExampleService.class); try { return service.listFeaturedAlbums().execute(); } catch (IOException …