我一直在尝试使用 REBOL 的 API 来访问该网站,但遇到了问题。 API 调用需要自定义 header 和 XML 格式的请求。我一直在尝试使用读取/自定义,但我不确定如何包含标题,或者它应该采用什么格式。 system/options/cgi 中的默认 header 是一个对象,所以我认为它应该是一个对象,但是你会把它放在哪里呢? (添加到 system/options/cgi 不起作用。)
我猜下面的代码类似于我需要的......
http-custom-header: make object! [
Content-Type: text/xml
etc...
]
xml-request: {
<?xml version="1.0" encoding="utf-8"?>
<etc>etc...<etc>
}
site-URL: http://etc...
response: read/custom site-URL reduce ['post xml-request]
这不会起作用,因为 http-custom-header 还没有被放置在任何有用的地方。
我走在正确的道路上吗?如果是这样,标题应该放在哪里?否则,使用 REBOL 发送 HTML header 和请求的可行方法是什么?
最佳答案
我已经弄清楚了。您只需将“ header ”和一个 block (而不是对象)添加到读取/自定义 block 中。因此...
http-custom-header: [
Content-Type: text/xml
etc...
]
xml-request: {
<?xml version="1.0" encoding="utf-8"?>
<etc>etc...<etc>
}
site-URL: http://etc...
response: read/custom site-URL reduce [
'header http-custom-header
'post xml-request
]
关于xml - 如何使用 REBOL 发送带有自定义 header 的 HTTP post,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691754/