如何使用 curl 在 Windows 下发布 PUT 请求?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4257490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:46:27  来源:igfitidea点击:

How to post PUT request under the Windows using curl?

windowshttpcommand-linecurl

提问by sergtk

I need to post XML data via curl.exe under windows using PUT request.

我需要使用 PUT 请求在 windows 下通过 curl.exe 发布 XML 数据。

In the curl help I found:

在 curl 帮助中我发现:

-d/--data <data>   HTTP POST data (H)

What should I supply for <data>?

我应该提供<data>什么?

回答by manuel aldana

curl sample calls

curl 示例调用

# with inlining plain data
curl -X PUT -d "payload" http://localhost
# referrring file
curl -X PUT -d @myXmlFile.xml http://localhost

If your windows curl-port does not support it go for cygwin. It is a linux-like environment for windows and also offers "a proper" curl.

如果您的 windows curl-port 不支持它,请选择cygwin。它是一个类似于 linux 的 Windows 环境,还提供“适当的”卷曲。

回答by Stefan

In windows, if a double-quoted argument itself contains a double quote character, the double quote must be doubled.

在 Windows 中,如果双引号参数本身包含双引号字符,则双引号必须加倍。

For example, enter 'This is "quoted" payload' as "This is ""quoted"" payload" which is very different than in Unix.

例如,输入 'This is "quoted" payload' 作为 "This is ""quoted"" payload",这与 Unix 中的非常不同。

Example:

例子:

curl -X PUT -d "This is ""quoted"" payload" http://localhost

回答by Paul Adamson

in windows you'll need to put the @ insidethe quotes for the file you're sending:

在 Windows 中,您需要将 @放在要发送的文件的引号

curl -XPUT --data-binary "@uploadme.txt"

otherwise you'll get weird errors as it tries to use the content of the file as the url:

否则你会得到奇怪的错误,因为它试图使用文件的内容作为 url:

curl: (6) Couldn't resolve host 'upload'
curl: (6) Couldn't resolve host 'me!'

(uploadme.txt contains "upload me!")

(uploadme.txt 包含“上传我!”)