retrofit2 java.lang.IllegalArgumentException: @Body parameters cannot be used with form or multi-part encoding. (parameter #1)


    FATAL EXCEPTION: main
        Process: com.xxx.xxx, PID: 19795
        java.lang.IllegalArgumentException: @Body parameters cannot be used with form or multi-part encoding. (parameter #1)
        for method MovieService.getCode
        at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:720)
        at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:711)
        at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.java:729)
        at retrofit2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.java:669)
        at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.java:333)
        at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:202)
        at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
        at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
        at java.lang.reflect.Proxy.invoke(Proxy.java:393)
        at $Proxy0.getCode(Unknown Source)
        at com.xxx.xxx.activity.xxx$1.onClick(xxx.java:73)
        at android.view.View.performClick(View.java:5207)
        at android.view.View$PerformClick.run(View.java:21177)
        at android.os.Handler.handleCallback(Handler.java:742)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:5544)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)

在使用retrofit2做请求 出现异常
原因是编码重复
在body中设置了编码,和注解中编码重复

  RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), object.toString());

 @FormUrlEncoded
  @POST("code")
   Call getCode( @Body RequestBody body);

解决办法
删除@FormUrlEncoded

详情:
https://stackoverflow.com/questions/27317096/retrofit-body-parameters-cannot-be-used-with-form-or-multi-part-encoding

你可能感兴趣的:(retrofit2 java.lang.IllegalArgumentException: @Body parameters cannot be used with form or multi-part encoding. (parameter #1))