【问题标题】:AWS API Gateway removing newlines from bodyAWS API Gateway 从正文中删除换行符
【发布时间】:2016-06-24 10:19:18
【问题描述】:

我的身体映射定义为:

{
    "csv": "$input.body",
    "p1": false,
    "p2": "p3",
    "p3": "p4"
}

调用函数

curl 'https://xxxxx.execute-api.us-west-2.amazonaws.com/prod/xxx?p3=aaa&p4=bbb' \
-XPOST -H "Content-Type: application/csv"  -d @input.csv

input.csv 包含的地方

l1c1,l1c2
l2c1,l2c2
l3c1,l3c2

最终会调用我的 lambda 函数

{
    "csv": "l1c1,l1c2l2c1,l2c2l3c1,l3c2",
    "p1": false,
    "p2": "p3",
    "p3": "p4"
}

有没有办法不从正文中删除换行符? $input.body 应根据此处的文档http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#d0e9653

评估为“RAW PAYLOAD”

也尝试使用 $util.escapeJavaScript($input.body),但它根本没有任何区别。

解码 $util.base64Encode($input.body) 也剥离了换行符...

谢谢,

【问题讨论】:

    标签: curl


    【解决方案1】:

    原来 --data 或 -d 将数据作为 www-form-urlencoded 发送,从而去除新行。 --data-binary 是在我的情况下发送文件的正确方法。

    【讨论】:

      【解决方案2】:

      来自 curl 的man page

      因此,将使用 --data @foobar 从名为“foobar”的文件发布数据。当 --data 被告知从这样的文件中读取时,回车符和换行符将被删除。

      另见:How to send line break with curl?

      【讨论】:

        猜你喜欢
        • 2022-06-10
        • 2017-01-24
        • 2019-08-12
        • 2019-10-25
        • 2014-05-21
        • 2022-10-06
        • 1970-01-01
        • 2017-11-30
        • 2021-12-30
        相关资源
        最近更新 更多