如何将数组添加到 okhttp 主体 (POST)
How to add array to okhttp body (POST)
现在我将数组作为字符串添加到主体中:
RequestBody body = new FormEncodingBuilder()
.add("profiles", "[122, 125, 336]")
.build();
但服务器需要 post 参数数组。我怎样才能添加数组而不是字符串? okhttp 可行吗?
您目前正在 profiles
作为字符串发布。您需要为 profiles
的复选框表单域模仿 POST
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
现在我将数组作为字符串添加到主体中:
RequestBody body = new FormEncodingBuilder()
.add("profiles", "[122, 125, 336]")
.build();
但服务器需要 post 参数数组。我怎样才能添加数组而不是字符串? okhttp 可行吗?
您目前正在 profiles
作为字符串发布。您需要为 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