Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

How to do CGI POST as client? - solved

 [1/9] from: dud:monmouth at: 15-Dec-2000 10:15


After a lot of false starts trying to get Rebol to successfully do a CGI POST operation, I finally figured out how to write a script that works. Bill Dudley P.S. I don't think Rebol is ready for prime time if the examples in the Core book don't all run correctly. Working script: #!/usr/local/bin/perl use LWP::UserAgent; $ua = new LWP::UserAgent; $ua->agent("AgentName/0.1 " . $ua->agent); @sites= ( "http://badminout.monmouth.com/cgi-bin/cgiwrap/dud/dsl.cgi", ); $data = "npa=\"732\"&nxx=\"842\"&process=Lookup"; foreach $url (@sites) { my $req = new HTTP::Request POST => $url; $req->content_type('application/x-www-form-urlencoded'); $req->content($data); my $res = $ua->request($req); if($res->is_success) { $res->content =~ s/<[^<>]*>//g; $res->content =~ s/^[ ]*\n//mg; print "$res->content"; } else { print "didn't work:\n$url $data\n"; } }

 [2/9] from: jeff:rebol at: 15-Dec-2000 9:33


Howdy, Bill: Regarding your attempt to use REBOL's http post stuff: Were you using the latest experimental version of core or released version, core 2.3? I think read/custom http:// [post {stuff}] is only in the latest experimental versions. [Yes, we here at rebol are sometimes unsure of what's where... :-) Though the goal of the experimentals is to get everything in the same place-- the release versions! (-: and for that goal we are working tirelessly!] -jeff

 [3/9] from: gchiu::compkarori::co::nz at: 16-Dec-2000 7:25


On Fri, 15 Dec 2000 10:15:43 -0500 "William F. Dudley Jr." <[dud--monmouth--com]> wrote:
> $data = "npa=\"732\"&nxx=\"842\"&process=Lookup"; >
If you had used the http-tools.r script I posted, it would have been data: [ "npa" "732" "xx" "842" "process" "Lookup" ] tmp: http-tools/post yourcgiscript data I went to your url the other day, but didn't go further as it was password protected! -- Graham Chiu http://www.compkarori.co.nz/index.r

 [4/9] from: doug:vos:eds at: 15-Dec-2000 13:51


Graham: Thanks again... I was also asleep... Please send out new http-tools.r or provide pointer. Thanks.

 [5/9] from: dud:monmouth at: 15-Dec-2000 14:01


Hi, thanks for the reply. Graham wrote:
> On Fri, 15 Dec 2000 10:15:43 -0500 > "William F. Dudley Jr." <[dud--monmouth--com]> wrote:
<<quoted lines omitted: 4>>
> data: [ "npa" "732" "xx" "842" "process" "Lookup" ] > tmp: http-tools/post yourcgiscript data
I've only been subscribed to rebol-list for a week or less so it probably went by before I subscribed. I checked the list archives for solutions to my problem, but the search engine there seems very poor in that it does not seem to filter out inappropriate posts very well.
> I went to your url the other day, but didn't go further as > it was password protected!
Really? I'm unaware of any password protection on http://badminout.monmouth.com/cgi-bin/cgiwrap/dud/dsl.cgi And I wrote it. It's designed to do a simple lookup in a mysql database to allow customers or even non-customers to see if DSL is available in their area. (The data only includes the parts of New Jersey that our ISP servers). So password protection would be contra-indicated. However, if you go to: http://badminout.monmouth.com/cgi-bin/cgiwrap/dud/index.cgi That IS password protected because it allows paying customers to create up to four free additional email addresses. Bill Dudley

 [6/9] from: gchiu:compkarori at: 16-Dec-2000 8:39


On Fri, 15 Dec 2000 13:51:13 -0500 "Vos, Doug" <[doug--vos--eds--com]> wrote:
> Thanks again... I was also asleep... > Please send out new http-tools.r or provide pointer. > > Thanks.
Hi Doug, It's in my signature below if you are using Rebol/View, or if not, at http://www.compkarori.co.nz/reb/http-tools.r the caveats posted the other day still apply. -- Graham Chiu http://www.compkarori.co.nz/index.r

 [7/9] from: dud:monmouth at: 15-Dec-2000 15:17


Graham,
> Actually, I posted my message *after* I saw you were having > problems. >
I just went back to my email archive and sure enough, I had saved your message on the off chance that it might be useful. But since it discussed cookies and authentication, did not realize that it was really (I'm guessing, now) a general-purpose http client package.
> As I was looking for the form. I didn't realise your cgi > script was the form. >
Sometimes I build my cgi engines to be state machines, so that if you visit it the first time, it shows you the top form, and then subsequent visits have the new state encoded into the hidden fields (or the submit button value) so that new pages are displayed.
> <input type=submit name=process value="Lookup"> > <input type=hidden name=process value="Lookup"> >
That "oddity" is an attempt to make the page work correctly if the user selects an npa (area code) from the drop down, and types in an nxx (exchange) in the box, and then hits the Enter key instead of clicking on the submit button. Bill Dudley

 [8/9] from: gchiu:compkarori at: 16-Dec-2000 9:27


This works for me: rebol [] do http://www.compkarori.co.nz/reb/http-tools.r cgi: http://badminout.monmouth.com/cgi-bin/cgiwrap/dud/dsl.cgi data: [ "npa" "732" "nxx" "842" "process" "Lookup" ] tmp: http-tools/post cgi data probe tmp/content -- Graham Chiu

 [9/9] from: dud:monmouth at: 15-Dec-2000 16:01


Thanks, that certainly is easy enough. Bill Dudley

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted