【问题标题】:Send an XML file using curl as metadata使用 curl 作为元数据发送 XML 文件
【发布时间】:2018-10-24 14:40:06
【问题描述】:

'我有一个巨大的 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 本身非常好。我只是把它剪下来贴在这里。

当我运行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>

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

【问题讨论】:

  • PUT 还是POST?你两个都用。
  • 我第一次尝试应该是PUT。但我也试过POST
  • 在您的元数据作业中添加引号 - METADATA="$(cat cost_meta.xml)"
  • 您的代码中 curl 的参数上方是否有空行?
  • 是的,空行是个问题。但现在我得到Invalid JSON provided as input. Could not parse the service provider's trust settings

标签: bash curl put


【解决方案1】:

你的脚本好像没问题,除了额外的换行符和对应的错误信息,加了-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)"'"}'

【讨论】:

  • 这确实消除了其中一个错误。但现在我得到Invalid JSON provided as input. Could not parse the service provider's trust settings
  • 更正了我的答案。
猜你喜欢
  • 2015-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-09
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多