如何做一个HTTP POST一个值列表使用cURL [英] how to do a HTTP POST a list of value using cURL

查看:168
本文介绍了如何做一个HTTP POST一个值列表使用cURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用cURL向同一个键发布多个值?



例如当我运行以下到我的example.com网址,它抱怨...

  curl -k -H'是正确的格式,或者这是后端无法处理请求的问题?接受:application / json'--user admin:admin example.com -d name = peter -d name = paul -d name = mary 


解决方案

多个 -d 看起来不错。文档表示 -d name = daniel -d skill = lousy 将生成 name = daniel& skill = lousy p>

http://curl.haxx .se / docs / manpage.html#-d



所以如果你想发送数组,你必须使用 [ ] 括号。

  -d name [] = peter -d name [] = paul -d name [] = mary 

看起来你也可以使用

  -dname [] = peter& name [] = paul& name = mary


how I do post multiple values to the same key using cURL?

for example when I ran the following to my example.com URL, it complained...is the format correct or is this a problem with the backend not being able to handle the request?

curl -k -H 'Accept: application/json' --user admin:admin example.com -d name=peter -d name=paul -d name=mary

解决方案

Multiple -d looks fine. The docs said -d name=daniel -d skill=lousy will generate name=daniel&skill=lousy

http://curl.haxx.se/docs/manpage.html#-d

So if you want send an array, you have to use the [] brackets.

-d name[]=peter -d name[]=paul -d name[]=mary

It looks like you can also use

-d "name[]=peter&name[]=paul&name=mary"

这篇关于如何做一个HTTP POST一个值列表使用cURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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