How to send an HTTP post with a custom header using REBOL

情到浓时终转凉″ 提交于 2019-12-11 02:44:36

问题


I've been trying to access a site with REBOL using the site's API, but I'm having problems. The API call expects a custom header and a request in XML format. I've been trying with read/custom, but I'm unsure how to include the header, or what format it should take. The default header in system/options/cgi is an object, so I assume it should be an object, but where would you put it? (Adding to system/options/cgi hasn't worked.)

I'm guessing the code below is something like what I need...

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]

That won't work though as http-custom-header hasn't been put anywhere useful.

Am I on the right track? If so, where should the header go? Otherwise, what's a workable way to send an HTML header and request using REBOL?


回答1:


I've figured it out. You just add 'header and a block (not an object) to the read/custom block. Thus...

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
]


来源:https://stackoverflow.com/questions/8691754/how-to-send-an-http-post-with-a-custom-header-using-rebol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!