linux - 如何使用 curl 命令行工具发布 LF?

标签 linux curl

我正在尝试使用来自 Linux shell 脚本的 CURL POST 到 SMS 提供商 (Sybase 365) 的 HTTP 网关。

我需要传递以下数据(注意 [ ] 和 LF 字符)

[MSISDN]
List=+12345678
[MESSAGE]
Text=Hello
[END]

如果我使用 -F 参数提交文件,CURL 会删除 LF,例如

curl -F @myfile "http://www.sybase.com/..."

在服务器上的结果(被拒绝)

[MSISDN]List=+12345678[MESSAGE]Text=Hello[END]

我能做些什么来避免这种情况,还是我需要一个替代工具?

我正在使用包含我的数据的文件进行测试,但我想在实践中避免这种情况并直接从脚本中发布。

最佳答案

尝试使用 --data-binary 而不是 -d(ata-ascii)

来自手册:

--data-binary (HTTP) This posts data in a similar manner as --data-ascii does, although when using this option the entire context of the posted data is kept as-is.

If you want to post a binary file without the strip-newlines feature of the --data-ascii option, this is for you. If this option is used several times, the ones following the first will append data.

ETA:糟糕,我应该更仔细地阅读这个问题。您使用的是 -F,而不是 -d。但是 --data-binary 可能仍然值得一试。

关于linux - 如何使用 curl 命令行工具发布 LF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/388365/

相关文章:

php - 如何在同一台服务器上使用 php curl 或 file_get_content 获取 url 内容?

linux - Cron 每分钟通过 CURL 触发 url

c++ - 学习特定于 Linux 的 API 是否有意义?

linux - “git remote”显示的 url 与 .git/config 中设置的不同

linux - Docker 卷不存储整个数据

linux - `for f in *; do cp "$f ""$f "_copy; done` 没有 't work because "foo.png_copy”。如何解决?

linux - CentOS rpm 包依赖于它使用 cmake 构建的 lib "soname"

PHP CURL 重定向

ssl - 使用 cURL 和 API v3 将视频上传到 YouTube 时出错

curl - 为什么使用curl时无法在aws上访问网站?