我想发送一个 HTTP post 请求,到目前为止一切都很好(我在这个应用程序中发送了 10+ 个请求(,但现在有一个问题。
我收到此错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Caused by: java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #2)
这是接口代码:
@POST("index.php/web/request")
Call<MyResponse> getMy(@Header("authorization") String token, MyRequest myRequest);
这是我的主要活动代码:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://link.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(MyAPI.class);
MyRequest myRequest = new MyRequest();
myRequest.setText(text);
final Call<MyResponse> myResponseCall = service.getMy(token, myRequest);
错误在此行中:
final Call<MyResponse> myResponseCall = service.getMy(token, myRequest);
您尚未注释第二个参数....它可以是@Body,@Query等。添加批注
将接口方法更改为
@FormUrlEncoded
@POST("index.php/web/request")
Call<MyResponse> getMy(@Header("authorization") String token);
或
@FormUrlEncoded
@POST("index.php/web/request")
Call<MyResponse> getMy(@Header("authorization") String token, MyRequest myRequest);
您可以使用@Body或使用@Filed("name_parameter"( 并在方法之上放@FormUrlEncoded。