在curl中使用-d发布多个文件 [英] POST multiple files with -d in curl
问题描述
我正在使用curl创建多个分类。我为许多分类编写了json,它们位于一个文件夹中。我想一次性创建所有分类。但是使用curl我只能一次创建一个。如何在一个请求中创建它们?
I'm using curl to create several classifications. I have written the json for the many classifications and they are in one folder. I would like to create all the classifications in one go. But using curl I can only create them one at a time. How could I make them in one request?
curl -u admin:admin -H "Content-Type: application/json" -X POST -d @pii.json http://127.0.0.1:21000/api/atlas/v2/types/typedefs
-d的curl手册说也可以指定多个文件。我怎样才能做到这一点?我所有的尝试都失败了。
The curl manual for -d says 'Multiple files can also be specified'. How can I do this? All my attempts have failed.
我需要bash脚本吗?如果是这样,您能帮我吗-我不是编码员,我在没有例子的情况下苦苦挣扎!
Do I need a bash script instead? If so, could you help me - I'm not a coder and I'm struggling without an example!
在此先感谢。
推荐答案
我发现以下内容最终可以工作:
I found the following to work in the end:
<fileToUpload.dat xargs -I % curl -X POST -T "{%}" -u admin:admin -H "Content-Type: application/json" http://127.0.0.1:21000/api/atlas/v2/types/typedefs
其中fileToUpload.dat包含.json文件列表。
Where fileToUpload.dat contained a list of the .json files.
这似乎可以解决丹尼尔的答案,这可能是由于文件的内容所致。如果Daniel的解决方案对他们不起作用,希望这对其他人有用。
This seemed to work over Daniel's answer, probably due to the contents of the files. Hopefully this is useful to others if Daniel's solution doesn't work for them.
这篇关于在curl中使用-d发布多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!