curl post 里面的 + 加号怎么不转义输出啊

2021-11-12 13:43:07 +08:00
 toyst
oldPath="ABC+ABC"
curl -G --data--urlencode "oldPath=$oldPath" www.abc.com

传过去报错 oldPath "ABC ABC" 不存在

"+" 变成了空格

怎么传 ABC+ABC 过去呢?

2079 次点击
所在节点    Linux
6 条回复
tsanie
2021-11-12 14:02:10 +08:00
--data--urlencode 表示你的 data 是 encoded 后的,去掉这个参数使用--data ,或者--data-urlencode "oldPath=ABC%2BABC"
honjow
2021-11-12 14:06:35 +08:00
去查下 urlencode 是啥
toyst
2021-11-12 16:20:35 +08:00
@tsanie 可是不 encode 原目录有中文字符怎么办啊
0608516518
2021-11-12 16:48:43 +08:00
请 post 到 http://httpbin.org/post ,就可以看到服务器视角得到了什么
toyst
2021-11-12 16:52:20 +08:00
```
* Trying 127.0.0.1:12345...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 12345 (#0)
> POST /api/v2/torrents/renameFile HTTP/1.1
> Host: 127.0.0.1:12345
> User-Agent: curl/7.68.0
> Accept: */*
> Cookie: SID=37qv44bvLPGK+9QMl5rmv/aNPNnaTqSYa
> Content-Length: 307
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 307 out of 307 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 409 Conflict
< connection: keep-alive
< content-length: 159
< content-security-policy: default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; script-src 'self' 'unsafe-inline'; object-src 'none'; form-action 'self';
< content-type: text/plain; charset=UTF-8
< date: Fri, 12 Nov 2021 08:50:10 GMT
< referrer-policy: same-origin
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
<
* Connection #0 to host 127.0.0.1 left intact
```
这是 -v 详细输出
msg7086
2021-11-14 04:06:28 +08:00
+ 就是空格。
%2B 才是 +。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/814924

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX