2.0.0-β1:利用改造发送多部分与文件 [英] send multipart with files using retrofit:2.0.0-beta1

查看:225
本文介绍了2.0.0-β1:利用改造发送多部分与文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,发送multipartRequest服务器。

I have problem with sending multipartRequest to server.

RequestBody file = RequestBody.create(MediaType.parse("application/json"), myFile);
        return apiService.updateProfile2(token, file);


@Multipart
@POST("/profile/update")
Call<RegistrationResponse> updateProfile2(@Header(value = "X-AUTH-TOKEN") String toke, @Part(value = "json") RequestBody json);

问题:

请求体是空的,当它来到的服务器

request body is empty, when it come to server

推荐答案

首先,请您尝试发送mediaType的应用程序/ JSON为@Multpart,如果你想发送multpartfile所以你需要改变出头的你code。

First all, do you are trying send the mediaType "application/json" as @Multpart, if you want send the multpartfile so do you needs change somethings in your code.

事情是这样的:

@Multipart
    @POST("/profile/update")
    Call<RegistrationResponse> updateProfile2(
    @Header(value = "X-AUTH-TOKEN") String toke,
    @Part("myfile\"; filename=\"image.png\" ") RequestBody file);

和改变调用方法如下:

RequestBody file = RequestBody.create(MediaType.parse("multipart/form-data"), myFile);
        return apiService.updateProfile2(token, file);

这篇关于2.0.0-β1:利用改造发送多部分与文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆