Home   Archive   Permalink

Submitting HTTP POST form info via a REBOL script to a PHP script

I would like to know if it is possible to use a REBOL script to send data using HTTP POST to a server that has a PHP script to handle the submission.
I have found info here http://www.rebol.com/docs/quick-start6.html that describes a way to send data using a REBOL form (in view) but to a server also running REBOL (core) to process the request.
I also found http://www.codeconscious.com/rebol/rebol-net.html that points to read/custom as a way to send POST info, as in:
print read/custom http://babelfish.altavista.com/translate.dyn
     reduce ['POST {text=REBOL+Rules&lp=en_fr}]
This example is repeated several times in a Google search but without further elaboration.
Checking 8.6 at http://www.rebol.com/docs/core23/rebolcore-13.html shows something similar but, again, oriented to a REBOL script at the server side. I also notice that the examples here omit printing what's returned to “read/custom”, which seems to be the HTML served by the server side script after the submission, although it does not report the success or failure of the submission.
Let's say that there is an HTML script that includes:
<form action='form-script.php' method='post'>
<input type='text' name='datum1'>
<input type='text' name='daum2'>
<input type='submit' name='send-button' value='send'>
I want to bypass the html and have a REBOL script on my computer, with access to the Internet, to send the data automatically. HTTP suggests that it should be possible.
would something like this work?:
read/custom http://thewebsite.com/form-script.php [ post “datum1: one-string datum2: another-string” ]
I based that line on the information found in the Internet but it didn't work.
Is it possible to do this? If so, what would be the proper syntax? Particularly, where would the quotes go if a string to be submitted includes spaces?
Thanks for any help

posted by:   Brother Damian       6-Nov-2015/3:27:17-8:00

It has been some time since I used this but my submit-form script should work for Rebol 2. There is a small example at the end of the script.
More recently I did work on another script (http://www.codeconscious.com/rebol-scripts/http.r) to do this in order to get a basic Trello interface working (http://www.codeconscious.com/rebol/articles/basic-trello-interface.html) but that may not be so easy to understand what it is doing. You would need to look at using http/send and http/request for that. I don't have an available example at the moment sorry.

posted by:   Brett       6-Nov-2015/6:57:20-8:00

As follow up.
http://requestb.in/ is a service to see a request.
You may wish to create your own request page, examples using mine with code "vuherjvu".
submit-form-example: does [
    do http://www.codeconscious.com/rebol/scripts/submit-form.r
    request-result: submit-form/post submit-url compose [
        {datum1} {one string}
        {datum2} {another string}
        {time} (form now)
    ?? request-result
    browse review-url
http-script-example: does [
    do http://www.codeconscious.com/rebol-scripts/http.r
    req: http/form/request 'post submit-url compose [
        {datum1} {one string}
        {datum2} {another string}
        {time} (now)
    request-result: http/send req
    ?? request-result
    browse review-url
sitecode: {vuherjvu}
submit-url: join http://requestb.in/ sitecode
review-url: join submit-url {?inspect}

posted by:   Brett       6-Nov-2015/15:01:09-8:00

I want to start by thanking Mr. Handley for the scripts that he so generously provided. Unfortunately, I am not versed enough with REBOL to completely understand what is written there. I am either too much of a novice or the scripts are really advanced (or both!). I must admit that I was not really looking for a solution but more for an explanation. I wasn't expecting to need close to 130 lines of code to perform a submission. Also, after running all 4 functions and submitting a name-value pair using the syntax described, the php script I have access to did not respond the way it would have if I had submitted the HTML form directly. Unfortunately again, I am not really able to explain why.
I would like to know if it possible to work with smaller building blocks of effective HTTP POST submission using REBOL in a way that I could learn from them before integrating them into a comprehensive solution. The documentation that I have found is descriptive but not very informative to me. I would really appreciate any information on this topic.
Thanks again Mr. Handley and please forgive that I wasn't prepared enough to learn from your examples.

posted by:   Brother Damian       9-Nov-2015/2:22:26-8:00

This is unexpected. With older versions such as http://re-bol.com/rebol121.exe the example above works as expected:
print read/custom http://localhost/phptest reduce ['POST {text=REBOL+Rules&lp=en_fr}]
The PHP script I used was simply:
<?php print_r($_POST); ?>
I'll have to look through Brett's script to see what's changed.
You can of course use GET:
print read http://localhost/phptest?test=hello
For the time being, the older version is a workaround...

posted by:   Nick       9-Nov-2015/12:11:23-8:00

It was still working as previously documented, in http://re-bol.com/rebcode_rebview1361031.exe

posted by:   Nick       9-Nov-2015/12:21:37-8:00

Really interesting - YES THIS POST ISSUE APPEARS TO BE A BREAKING CHANGE (and in a way which I haven't seen documented), in VERSION 2.7.8 (the current default R2 download). If you want to do POST operations, I would suggest using 2.7.6 until there's some discussion. I put a copy here:
For most uses, the 2.7.6 version should be totally usable. If I remember correctly, one of the biggest breaking changes that stood out for me between 2.7.6 and 2.7.8 was the way the default use of 'call was no longer /show (i.e., 'call/show needed to be used if you wanted to see an external running app which was started with 'call). I still have a number of machines on which 2.7.6 is installed and used interchangeably with 2.7.8.

posted by:   Nick       15-Nov-2015/12:22:35-8:00

Brett, on which version(s) have you tested your scripts above?

posted by:   Nick       15-Nov-2015/12:32:11-8:00

Interesting, this service works as expected with 2.78:
editor read/custom http://www.webservicex.net/globalweather.asmx/GetWeather reduce ['POST {CityName=New%20York&CountryName

posted by:   Nick       5-Dec-2015/9:07:19-8:00