使用 curl 作为元数据发送 XML 文件

Send an XML file using curl as metadata

'我有一个巨大的 XML 文件,我需要将其放入端点。我的 curl 命令目前看起来像:

curl -X PUT --user user:pass https://<end-point>/foo/bar/id \

    -H 'Content-Type: application/json' \

    -d '{
  "medata": "${METADATA}"
}'

我的 METADATA 来自 :

METADATA=$(cat cost_meta.xml)

cost_meta.xml大致如下:

<?xml version="1.0" encoding="UTF-8"?>
<md:EntityDescriptor ID="_ydkjknxyky6vepon" 
.
.
index="0"/></md:SPSSODescriptor></md:EntityDescriptor>

XML 本身完全没问题。我刚刚在此处将其缩减为 post。

当我 运行 curl 命令时,我得到错误

Failed to upsert service provider due to invalid JSON input.zsh: command not found: -H
zsh: command not found: -d

所以我尝试了另一种方式:

curl -H "Content-Type: text/xml" -d @cost_meta.xml -X POST --user user:pass https://<end-point>/foo/bar/id

但这给了我一个

的错误
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>417 Expectation Failed</title>
</head><body>
<h1>Expectation Failed</h1>
<p>The expectation given in the Expect request-header
field could not be met by this server.
The client sent<pre>
    Expect: 100-continue
</pre>
</p><p>Only the 100-continue expectation is supported.</p>
</body></html>

所以我不确定下一步该做什么。任何想法我做错了什么?

你的脚本似乎没问题,除了额外的换行符和对应的错误消息,添加一个-H 'Expect:',所以写

curl -X PUT --user user:pass https://<end-point>/foo/bar/id \
     -H 'Content-Type: application/json' -H 'Expect:' \
     -d '{"medata": "'"$(cat cost_meta.xml)"'"}'