如何添加自定义标头以改装请求正文部分? [英] How to add custom header to retrofit request body part?

查看:66
本文介绍了如何添加自定义标头以改装请求正文部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用改型构建多部分请求,并且我想向其中一部分添加自定义标头.我已经尝试了很多东西,但似乎没有任何效果.

So I am building a multipart request using retrofit and I want to add a custom header to one one of the part. I have tried a lot of things but nothing seems to be working.

照片显示了一个包含4个部分的正文请求.每个零件都包含一个主体和一个标题,我想要的是向所选零件添加自定义标题.我该怎么办?

The photo shows a body request that contains 4 parts. Each part contains a body and a header, what I want is to add a custom header to the selected part. How can I do that?

推荐答案

因此,为了回答我自己的问题,我创建了一个带有图像和自定义标头的零件,如下所示:

So just to answer my own question, I create a part with an image and a custom header like this:

MultipartBody.Part body = MultipartBody.Part.create(
    Headers.of("Content-Disposition", "form-data; name=\"" + "namevalue" + "\";" + " filename=\"" + filenamevalue + "\"", custom_header_name, custom_header_value),
    RequestBody.create(MediaType.parse("image/jpeg"), multimedia.getMedia())
);

这篇关于如何添加自定义标头以改装请求正文部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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