简体   繁体   中英

How to post just Array in retrofit Body for Android

In body I want to send just an ArrayList just as below

["item1","item2"]

And my API call is as below

@POST("{userId}/items")
fun postUpdateItems(
    @Path ("registrationId") registrationId: String,
    @Header(NetworkUtils.CONTENT_TYPE) contentType: String = NetworkUtils.CONTENT_TYPE_PARAMS,
    @Body body: List<String>
): Observable<Response<UpdateItemsResponse>>

But it does not work. I got the below error. I tried ArrayList Array None of them worked for me.

java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body.

I found the issue. It was not the "userId" . userId is a pathParam and should be added when we call the method. The issue was on the Handler. I was calling the wrong method.

I also have getUpdatedItems and on the handler I was calling it instead of postUpdateItems method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM