Hanbit the Developer
[Retrofit2] Send Post Request With Empty Body 본문
As you see in title, I'd like to say that codes in this post is for POST request with empty body, which means ... body: {}.
First of all, Set your api as below:
interface YourApi {
@POST("api/YOUR_ROUTE")
fun yourFunction(@Body body: RequestBody): Call<YourDto>
}
}
You will pass RequestBody in parameter. And the RequestBody is like as follows:
val body = RequestBody.create(MediaType.parse("application/json; charset=UTF-8"), "{}")
Finally, you create retrofit as originally you do.
val call = retrofit.create(YourApi::class.java).yourFunction(body)
// SKIP enqueue
'Android' 카테고리의 다른 글
[Kotlin] Set indent to first line of TextView in android (0) | 2021.08.10 |
---|---|
[Kotlin] TextView의 더보기 기능 구현 (0) | 2021.08.08 |
[Retrofit2 / OkHttpClient] Send Post Request With JWT(Bearer) Token (0) | 2021.07.21 |
[kakaomap] 현재 위치 마커 커스텀 이미지로 변경하기 (0) | 2021.07.09 |
[Kotlin] "전화하기" 기능 구현(4줄) (0) | 2021.07.02 |