gpt4 book ai didi

http - 使用 curl 时在 meteorjs 中发布数据

转载 作者:可可西里 更新时间:2023-11-01 16:37:27 27 4
gpt4 key购买 nike

我有以下方法将数据发布到服务器:

 curl --ipv4  http://localhost:3000/api/tests/1 -d @test.csv

我正在尝试将带有 curl 的文件发布到仪表应用程序

在 meteor 中我无法读取数据,因为我无法将 key 附加到 curl 选项数据作为 key 本身到达

例子

contents of test.csv  = > 1,1,1

在服务器上

console.log('route to host' , this.request.body); yields {{1,1,1} : ''}

是的,我什至尝试过 -F data=@test.csv 也没有成功

如何在通过curl 发帖时添加一个键并将文件的内容作为值?

最佳答案

基本上 -d for curl 意味着读取文件并将其内容用作数据

If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar. When --data is told to read from a file like that, carriage returns and newlines will be stripped out. If you don't want the @ character to have a special interpretation use --data-raw instead.

为了发送文件本身,你需要类似 -F 的东西

(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388. This enables uploading of binary files etc. To force the 'content' part to be a file, prefix the file name with an @ sign. To just get the content part from a file, prefix the file name with the symbol <. The difference between @ and < is then that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the contents for that text field from a file.

Example, to send your password file to the server, where 'password' is the name of the form-field to which /etc/passwd will be the input:

curl -F password=@/etc/passwd www.mypasswords.com

在你的情况下可能使用 -Fcurl --ipv4 http://localhost:3000/api/tests/1 -F数据=

如果你想将文件作为文件上传使用-F data=@test.csv

关于http - 使用 curl 时在 meteorjs 中发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30291847/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com