gpt4 book ai didi

curl - 如何使用 curl 将 xml 数据发布到一个简单的服务器

转载 作者:IT王子 更新时间:2023-10-29 02:37:11 24 4
gpt4 key购买 nike

我正在尝试放松身心。我在这里找到了一个例子:go example

我尝试使用 curl 来发布数据:

curl -H "Content-Type: text/xml"  -X POST -d "<Product><Id>1</Id><Title>The First</Title></Product>" localhost:8080/products

但是没有用。我的问题是:

  1. 本例如何使用curl发布数据?

  2. 这个程序如何使用 将 xml 数据读取到结构中?

    err := req.ReadEntity(updatedProduct)

(在其他例子中,req.ReadEntity是能够读取json数据的。这个单一的函数如何将数据读取到不同的结构中?)

谢谢:)

最佳答案

由于某些原因,该库无法识别 text/xml header ,您应该使用 application/xml

Check the source code

const (
MIME_XML = "application/xml"
.....

这是区别 rfc3023 :

If an XML document -- that is, the unprocessed, source XML document -- is readable by casual users, text/xml is preferable to application/xml. MIME user agents (and web user agents) that do not have explicit support for text/xml will treat it as text/plain, for example, by displaying the XML MIME entity as plain text. Application/xml is preferable when the XML MIME entity is unreadable by casual users.

关于curl - 如何使用 curl 将 xml 数据发布到一个简单的服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51607677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com