bash - bash, braces and quotes and curl -d
问题描述
I'm trying to send some headers and key value pairs of data to my server using curl. It looks like I'm getting a bash quoting problem, my key value pairs are being treated like hosts.
curl -v --header "Content-Type: application/json" \
--header "Foo: Bar 123456" \
-d \"\{ "baz": "glern", "froboz": "foo again"\}\" \
https://example.com > foo.html 2> error.txt
example.com is telling me:
HTTP 404 Not Found: URL or Document not found (dns_unresolved_hostname)
HTTP 404: Your requested host "baz" could not be resolved by DNS. The document at the specified URL does not exist.
HTTP 404 Not Found: URL or Document not found (dns_unresolved_hostname)
HTTP 404: Your requested host "glern," could not be resolved by DNS. The document at the specified URL does not exist.
and error.txt starts off like this:
* Rebuilt URL to: baz:/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 10.196.133.236...
* TCP_NODELAY set
* Connected to http.proxy.mycompanyproxy.com (10.196.133.236) port 8000 (#0)
> POST http://baz:/ HTTP/1.1
> Host: baz
> User-Agent: curl/7.54.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> Content-Type: application/json
> Foo: Bar 123456
> Content-Length: 2
> } [2 bytes data]
* upload completely sent off: 2 out of 2 bytes
< HTTP/1.1 404 Not Found
...
I certainly don't mean to hit the hosts baz, glern, etc... and it certainly looks like a shell quoting problem. But after trying many different things, like adding extra \" near the existing bare " around my key value pairs, I'm a bit lost here.
解决方案
在 之后-d
,仅\"\{
形成一个论据-d
。目前还不清楚你在追求什么,但也许:
curl -v --header "Content-Type: application/json" \
--header "Foo: Bar 123456" \
-d '{ "baz": "glern", "froboz": "foo again"}' \
https://example.com > foo.html 2> error.txt
这样,论点-d
是:
{ "baz": "glern", "froboz": "foo again"}
没有要求在包含大量双引号的字符串周围使用双引号;那只会让生活更艰难。
推荐阅读
- python - 根据python中嵌套列表中的另一个元素返回一个元素
- swift - Eureka Swift ViewRow - UIButton 不会点击
- r - 提高循环内 bind_rows 的速度(3000 个数据帧)
- c# - Nest 聚合返回错误 {Invalid NEST response built from an unsuccessful low level call on POST: /people/_search?typed_keys=true}
- python - 如何从熊猫数据框中删除互惠记录?
- mysql - 检查数据库 MySQL 中是否存在值数组
- tcl - '|' 有什么用 在TCL加盟运营?
- javascript - Jquery Datatable 按钮未显示在 React js 上
- matlab - 如何在 Matlab 中拟合多峰对数正态分布?
- c - 如何使用中断而不是偶尔发生,环形缓冲区实现问题