如何将数组添加到okhttp正文(POST) [英] How to add array to okhttp body (POST)

查看:122
本文介绍了如何将数组添加到okhttp正文(POST)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我将数组作为字符串添加到正文:

Now i`m adding array as string to body:

RequestBody body = new FormEncodingBuilder()
    .add("profiles", "[122, 125, 336]")
    .build();

但是服务器需要post参数上的数组.如何添加数组而不是字符串? okhttp可以吗?

But the server need array on post parameter. How can i add array instead of string? Is it posible with okhttp?

推荐答案

您当前正在以字符串形式发布profiles.您将需要为profiles

You are currently posting profiles as a string. You will want to mimic a POST for a checkbox form field for profiles

RequestBody body = new FormEncodingBuilder()
    .add("profiles[0]", "122")
    .add("profiles[1]", "125")
    .add("profiles[2]", "336")
    .build();

更多信息和良好阅读,

  • https://teamtreehouse.com/community/how-to-handle-multiple-checkboxes-values-in-a-form-using-php
  • Get $_POST from multiple checkboxes

这篇关于如何将数组添加到okhttp正文(POST)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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