I want get RSS code from a URL with Retrofit
and if I enter url staticly in the get annotation everything is OK but with dynamic url I get an error.
My
This happened to me when I was using suspend functions in the network service interface like so.
interface Service {
@GET("chapters")
suspend fun fetchChapters() : List<NetworkChapter>
I solved it by doing 2 things. 1. Using Gson instead of Moshi library. Remove moshi converter from retrofit and use Gson converter. 2. Removing coroutine converter factory from retrofit. I think this one was the main problem.
Also make sure you add @Query
or @Field
for all the parameters , depending on whether you issuing GET/POST.
eg:
@GET("/api/Books/GetAll")
void GetRecentBooks(@Query int Offset, Callback<List<Book>> cb);
Remove from retrofit interface all parameters that not belong to this.
I forgot to add @Field("")
Previously
@POST("/api/verify-phone")
@FormUrlEncoded
fun sendOTP(phone_number: String): Observable<SignInResponse?>
Fixed
@POST("/api/verify-phone")
@FormUrlEncoded
fun sendOTP(@Field("phone")phone_number: String): Observable<SignInResponse?>
Please check the Path
class you are using and make sure that the package is retrofit2.http.Path
instead of org.simpleframework.xml.Path
.
It is a common Retrofit annotation mistake.
In my case, I just forgot to remove Callback parameter for the service call when I start using retrofit 2. Make sure you didn't do the silly mistake I did.