[REBOL] Re: POST
From: tim:johnsons-web at: 27-Jun-2003 7:39
* alekk <[termin--terminal--sky--pl]> [030627 01:15]:
> > On Thu, 26 Jun 2003 10:57:10 -0500
> > "Harbaugh, John" <[John--Harbaugh--capmetro--org]> wrote:
> > >
> > >Can someone send me a form that works, a simple form
> > >please.
> > >
> > >The ones that are posted do not work correctly.
> >
> > Hi John,
> >
> > See http://www.rebol.com/docs/cgi2.html#section-4.2
> >
> > --
> > Graham Chiu
>
> In fact script in this tutorial doesn't work with - for example - PWS.
>
> Use this - which reads exact size of data (sorry - but i don't remember the
> author).
>
> input-cgi: func [/stdin] [
> stdin: make string! 15000
> either system/options/cgi/request-method = "POST" [
> use [Length] [
> Query: make string!
> Length: 2 + to-integer system/options/cgi/content-length
> read-io system/ports/input Query Length
> Query
> ]
> ][
> system/options/cgi/query-string
> ]
> ]
I haven't used the following on PWS, but I recommend Andreas'
approach because of potential buffering of stdin with large amounts
of data:
;;======================================================================================================
;; Courtesy of Andreas Bolka <[andreas--bolka--gmx--net]>
;;======================================================================================================
read-post-data: func [
{Reads the HTTP entity body}
/safe "Disables evaluation of content-length header."
/local len data tmp
] [
len: load any [ all [ safe "65536" ] system/options/cgi/content-length "0" ]
data: make string! len
tmp: make string! len
while [ 0 < read-io system/ports/input tmp len ] [
insert tail data tmp
clear tmp
]
data
] ; end: sub
;; The 'while loop checks the return value from read-io to ensure
;; that all data is read.
;; Good work Andreas!
~tj~
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
http://www.johnsons-web.com