【问题标题】:Form-data post request android studio表单数据发布请求android studio
【发布时间】:2021-08-09 03:16:11
【问题描述】:

我正在尝试创建表单数据发布请求,尝试使用@Part, @Field, @FieldMap, and @Body,但也没有成功。我通过邮递员测试了请求,它工作正常,但每次在 Android Studio 中,都会出现相同的错误

java.io.EOFException: End of input at line 1 column 1 path $ 

尝试

1.  @Multipart
    @POST("/forum/")
    Observable<Comment> postComment(
            @Part("content") RequestBody comment,
            @Part("type") RequestBody type,
            @Part("parent_id") RequestBody parent_id

    );

2.  @POST("/forum/")
    @FormUrlEncoded
    Observable<Comment> postComment(
            @Field("content") String comment,
            @Field("type") String type,
            @Field("parent_id") String parent_id

    );

3.  @POST("/forum/")
    @FormUrlEncoded
    Observable<Comment> postComment(
            @FieldMap Map<String, String> params
    );

4.  @POST("/forum/")
    //@Multipart
    Observable<Comment> postComment(
            @Body RequestBody body
    );

虽然在 Postman 上工作正常:

【问题讨论】:

    标签: java android retrofit form-data


    【解决方案1】:

    实际上,API 端需要四个参数,而我传递了三个。缺少一个参数

    @POST("/forum/")
        @FormUrlEncoded
        Observable<Comment> postComment(
                @Field("creator_id") String creator_id,
                @Field("content") String comment,
                @Field("type") String type,
                @Field("parent_id") String parent_id
    
        );
    

    【讨论】:

      猜你喜欢
      • 2021-05-14
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-05
      相关资源
      最近更新 更多