How to send HTTP POST requests using only Rebol3
Asked Answered
C

1

7

What is the simplest way of sending HTTP POST requests and getting response (in XML format for example) using only Rebol3?

Is there an equivalent of using read/custom in Rebol2, as it is done in this question?

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

And where should I be donwnloading my Rebol3 binaries from? I've not found a lot of documentation on that...

Clematis answered 4/10, 2013 at 13:44 Comment(1)
I don't know the answer, but at one point I found that if you use WRITE on an http://-style URL then it automatically turned it into a POST for you... which is cool.Valiancy
B
6

The documentation at on Ports: Synchronous and Asynchronous Operations shows how to use both GET and POST. To summarize:

The default behavior is to assume the post data should be considered as application/x-www-form-urlencoded. (If you want to encode a block of ordinary Rebol data into that format, see %altwebform.r)

result: write http://www.rebol.com/cgi-bin/updata.r data 

If you need a custom header, then instead of passing a string you need to pass a block. Start it with the WORD! post followed by a block of Rebol-formatted key/value pairs, and then your data:

result: write http://www.rebol.com/cgi-bin/updata.r compose [
    post [
        Content-type: "text/x-rebol"
        ;-- other fields here
    ]
    (data)
]

The result will be in binary! and can be converted to string! to parse out any XML or whatever.

where should I be downloading my Rebol3 binaries from?

You should download binaries from http://www.rebolsource.net/

Briannebriano answered 4/10, 2013 at 23:8 Comment(2)
Thanks a lot, Graham. Tested at office with real SOAP web services. Amazing how it is simple !Clematis
This also works in Rebol 2 read/custom url compose [post (d) [Content-Type: "text/xml" ] ] Note that read/custom url compose [post (d) header [Content-Type: "text/xml" ] ] doesn't work.Outlier

© 2022 - 2024 — McMap. All rights reserved.