How to send an HTTP post with a custom header usin

2019-07-16 05:21发布

问题:

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
]