如何使用okhttp MultipartBuilder数据发送字符串数组数据 [英] How to send string array data with okhttp MultipartBuilder data

查看:95
本文介绍了如何使用okhttp MultipartBuilder数据发送字符串数组数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名Android开发人员.我开发一个应用程序.我有个问题.我想使用okhttp多部分数据发送字符串数组数据.但是我做不到.因为"addFormDataPart"方法是必需的字符串变量.我不能使用该方法(addFormDataPart).我想发送字符串数组数据.我能做些什么?

I am an android developer. I develop an application. I have a problem. I want to send string array data with okhttp multipart data. But I can not do it. Because "addFormDataPart" method is required string variable. I can not use that method(addFormDataPart). I want to send string array data. What can I do?

请帮助我.

我的源代码:

private void String sendData(String serverURL, String[] arrayData){
RequestBody requestBody;
requestBody = new MultipartBuilder()
                        .type(MultipartBuilder.FORM)
                        .addFormDataPart("arraydata", arrayData)
                        .build();
}

推荐答案

    void String sendData(String serverURL, String[] arrayData){
        String commaSeparatedValues = TextUtils.join(",", arrayData);
        multiPartBuilder.addFormDataPart("key[]", commaSeparatedValues);
    }

注意:这里的键很重要,它应该有"[]"

Note: the key here is important it should have "[]"

这篇关于如何使用okhttp MultipartBuilder数据发送字符串数组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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