Newbie: Trouble filling a form using "http-post.r"
[1/10] from: kimm2::mcmaster::ca at: 1-Jun-2002 0:46
Hi, I'm very new at REBOL and I'm stuck!
I'm trying to write code that will automatically fill out the form on
http://www.rogers.com/english/wireless/sendpcs.html, but I get this
error:
Error: HTTP/1.1 405 Method Not Allowed
What does this mean?
In the http-post.r code, within the "english-to-german" function
(although I'm not using the rogers.com website to translate anything),
I've modified it to look like this.
tmp: http-post-form
http://www.rogers.com/english/wireless/sendpcs.html reduce [
"area" "416"
"num1" "555"
"num2" "5555"
"text" "testing"
]
Can someone please help?
Thanks in advance.
[2/10] from: gchiu:compkarori at: 1-Jun-2002 20:38
> Error: HTTP/1.1 405 Method Not Allowed
> tmp: http-post-form
<<quoted lines omitted: 6>>
> ]
> Can someone please help?
You need to post to the CGI script at
http://216.129.53.44:8080/cgi-bin/send_sm_rogers.new
and not to the webpage where the form resides.
--
Graham Chiu
[3/10] from: kimm2:mcmaster:ca at: 7-Jun-2002 19:15
I tried this, but it still doesn't seem to work. Perhaps its my lack of
familiarity with HTTP. Could someone help me out please? It looks
relatively simple...
Are "area" "num1" "num2" and "text" the only variables that need to be
defined?
Thanks in advance,
Matt
> Error: HTTP/1.1 405 Method Not Allowed
> tmp: http-post-form
<<quoted lines omitted: 6>>
> ]
> Can someone please help?
You need to post to the CGI script at
http://216.129.53.44:8080/cgi-bin/send_sm_rogers.new
and not to the webpage where the form resides.
--
Graham Chiu
[4/10] from: cybarite:sympatico:ca at: 7-Jun-2002 22:24
Matthew,
If you take a copy of the data entry source page, you can edit it and change
it from POST to GET
in the line containing <FORM METHOD=POST ACTION="......."
save this editted html file on your computer, then open it with your
browser, enter some data and hit the submit button.
A failed message will be displayed by the server but in the URL you should
be able to see what was sent.
When I did this I got back this
http://216.129.53.44:8080/cgi-bin/send_sm_rogers.new?
msisdn=4165551212
&area=416&num1=555&num2=1212
&oldtext=This+is+a+test+to+see+w+hat+is+posted.
&text=This+is+a+test+to+see+w+hat+is+posted.
&SIZEBOX=38
&sm_title=Rogers+%7C+Wireless&sm_header_ok=Thank+You
&sm_header_fail=Sorry
&sm_ym=Your+Message%3A+
&sm_status_ok=has+been+sent+to%3A
&sm_status_fail=cannot+presently+be+sent+to%3A+
&sm_logo=%2Fatt-logo.gif
&sm_pcs_link=http%3A%2F%2Fwww.rogers.com%2Fenglish%2Fwireless%2Fsendpcs.html
&sm_pcs_text=Send+a+PCS+message
&sm_home_link=http%3A%2F%2Fwww.rogers.com
&sm_home_text=home
maybe you need to submit SIZEBOX or msisdn which looks like it is a copy of
the phone number.
Give it a try.
[5/10] from: kimm2:mcmaster:ca at: 8-Jun-2002 1:05
Hey, that's a pretty neat trick!
Well, I tried what you suggested, but it still doesn't seem to work. I
also tried using all the variables listed included
sm_logo
sm_status_ok
etc...
but that still didn't work.
Am I interpreting the REBOL code properly? For instance, is this
correct?
english-to-german: func [
; {Translates a string in English to German, using
babelfish.altavista.com}
; english-text "String in english"
;][
not-lt-gt: complement charset [#"<" #">"]
tag-rule: ["<" some not-lt-gt ">"]
tmp: http-post-form
http://216.129.53.44:8080/cgi-bin/send_sm_rogers.new reduce [
"msisdn" "4165551212"
"area" "416"
"num1" "555"
"num2" "1212"
"oldtext" "testing"
"text" "testing"
"SIZEBOX" "7"
"sm_title" "Rogers+%7C+Wireless"
"sm_header_ok" "Thank+You"
"sm_header_fail" "Sorry"
"sm_ym" "Your+Message%3A+"
"sm_status_ok" "has+been+sent+to%3A"
"sm_status_fail" "cannot+presently+be+sent+to%3A+"
"sm_logo" "%2Fatt-logo.gif"
"sm_pcs_link"
http%3A%2F%2Fwww.rogers.com%2Fenglish%2Fwireless%2Fsendpcs.html
"sm_pcs_text" "Send+a+PCS+message"
"sm_home_link" "http%3A%2F%2Fwww.rogers.com"
"sm_home_text" "home"
]
[6/10] from: cybarite:sympatico:ca at: 8-Jun-2002 8:13
Matthew,
I looked into my cached copy of http-post.r which is what I have that is
reading the alta-vista site.
It was not working because the alta vista site has changed since it was
written.
The url is different and the formatting of the results are different.
This is one of the challenges of reading a user interface screen for data.
If you save this html content as a file on your machine:
html><head><title>Basic Babel</title></head>
<body bgcolor=linen>
<form action="http://babelfish.altavista.com/tr" method=get>
<textarea rows="6" wrap=virtual cols="38" style="width:400" name="urltext"
>This is a test</textarea>
<input type="hidden" name="enc" value="utf8"><br>
<input type="hidden" name="lp" value="en_de"><br>
<input type="Submit" value="Translate">
<input type="hidden" name=tt value="urltext">
</td>
</form>
</body></html>
and submit it through your browser you will see a result page from the
translation.
Then you can see what you have to change the example to.
I will look at the Rogers example later ... much later.
[7/10] from: gscottjones:mchsi at: 8-Jun-2002 16:57
From: "Matthew Kim"
<snip>
> Well, I tried what you suggested, but it still doesn't seem to work. I
> also tried using all the variables listed included
<snip>
> but that still didn't work.
<snip>
Hi, Matthew,
I was asleep at the wheel during your original posting, and I hope I haven't
overlooked something critical in one of the follow-ups. Using Cybarite's
info, you just need to add a few more details to do a proper post in REBOL.
You will need to add the post request with by using 'read/custom and then
'reduce a block that contains the word 'POST and a block containing the
info. The variable names will need an "=" symbol following the variable.
There appeared to be a variable missing, SIZEBOXW, which is the count of the
words in the message. Here is the new request (note that the return is
assigned to 'page) (watch for wrapped lines, especially the first!!):
page: read/custom http://216.129.53.44:8080/cgi-bin/send_sm_rogers.new
reduce [
'POST rejoin [
"msisdn=" "4165551212"
"area=" "416"
"num1=" "555"
"num2=" "1212"
"oldtext=" "testing"
"text=" "testing"
"SIZEBOX=" "7"
"SIZEBOXW=" "1"
"sm_title=" "Rogers+%7C+Wireless"
"sm_header_ok=" "Thank+You"
"sm_header_fail=" "Sorry"
"sm_ym=" "Your+Message%3A+"
"sm_status_ok=" "has+been+sent+to%3A"
"sm_status_fail=" "cannot+presently+be+sent+to%3A+"
"sm_logo=" "%2Fatt-logo.gif"
"sm_pcs_link="
"http%3A%2F%2Fwww.rogers.com%2Fenglish%2Fwireless%2Fsendpcs.html"
"sm_pcs_text=" "Send+a+PCS+message"
"sm_home_link=" "http%3A%2F%2Fwww.rogers.com"
"sm_home_text=" "home"
]
]
I have no way to verify that this actually works. But hopefully the posting
method is correct.
You sure picked a hard one for an early project. If the method above is
still not working, then there are potentially other things going on,
including that the site monitors for the name of the browser, and may not
recognize REBOL. To get the hang of using a post method in REBOL, I would
suggest finding a much simpler form (like babelfish's) and be sure that you
have it working well before tackling what I would consider a much more
difficult form.
Hope this helps some, and good luck.
--Scott Jones
[8/10] from: cybarite:sympatico:ca at: 9-Jun-2002 8:02
Matthew,
I don't know if you got Scott's approach working or not.
He is using the more native approach rather than what is in %http-port.r
For the rogers message, this html seems to allow a post with <all | most> of
the extraneous html (and javascript) removed
<html><head><title>Mr Rogers</title></head>
<body bgcolor=linen>
<form ACTION="http://216.129.53.44:8080/cgi-bin/send_sm_rogers.new"
method=POST>
<INPUT TYPE="submit" VALUE="send message">
<INPUT type="hidden" name="msisdn" value="4165551212">
<input type="hidden" name="num1" value="416">
<input type="hidden" name="num2" value="5551212">
<input type="hidden" name="text" value="This is a test">
<input type="hidden" name=sizebox value="14">
<input type="hidden" name="sm_title" value="Rogers | Wireless">
<input type="hidden" name="sm_header_ok" value="Thank You">
<input type="hidden" name="sm_header_fail" value="Sorry">
<input type="hidden" name="sm_ym" value="Your Message: ">
<input type="hidden" name="sm_status_ok" value="has been sent to:">
<input type="hidden" name="sm_status_fail" value="cannot presently be sent
to: ">
<input type="hidden" name="sm_logo" value="/att-logo.gif">
<input type="hidden" name="sm_pcs_link"
value="http://www.rogers.com/english/wireless/sendpcs.html">
<input type="hidden" name="sm_pcs_text" value="Send a PCS message">
<input type="hidden" name="sm_home_link" value="http://www.rogers.com">
<input type="hidden" name="sm_home_text" value="home">
</form>
</body></html>
I did not look at their approach too long but I think they are passing some
parameters to the cgi message that are then echoed back on the response.
So the original posting message already knows the logo, and possible error
or success messages.
For example, you can change the success message to "has, we think, really
been sent to:"
I think this is clever ... allowing you to control some output on the
response page and make your parsing work easier.
And making you a bit more independent of changes to the processing program.
If you want to use the functions in http-post.r then you can add a new one
that allows a message to be sent
For example, this send-message function works for me using the values show
and it uses the http-post-form function from http-post.r
send-message: func [
{Sends a message}
area-code
phone-number
message
][
not-lt-gt: complement charset [#"<" #">"]
tag-rule: ["<" some not-lt-gt ">"]
tmp: http-post-form
http://216.129.53.44:8080/cgi-bin/send_sm_rogers.new? reduce [
"msisdn" join area-code phone-number
"num1" area-code
"num2" phone-number
"oldtext" ""
"text" message
"SIZEBOX" to-string length? message
"submit" "send message"
"sm_ym" "Your Message: "
"sm_status_ok" "has been sent to:"
"sm_status_fail" "cannot presently be sent to: "
"sm_logo" "/att-logo.gif"
"sm_home_link" "http://www.rogers.com"
"sm_home_text" "home"
]
if none? find tmp/HTTP-Response "200" [return join "Error: "
tmp/HTTP-Response]
either parse tmp/content [ ; very ugly
parsing attempt
thru "Your Message: <br>" to {</b><br>} thru "<br>" copy trans to
{</font>} to end ; changed parse value
][
return trans
][
print ["Content was: " tmp/content]
return "Error: Unable to parse HTML result page"
]
]
print send-message "416" "5551212" "This is a test"
but note the comment about the parsing... very ugly and very specific (and
limited) to this example.
[9/10] from: gscottjones:mchsi at: 9-Jun-2002 19:44
From: "Cybarite"
<snip>
> I don't know if you got Scott's approach working
> or not. He is using the more native approach rather
> than what is in %http-port.r
Whoops. See, I was asleep at the wheel. Just call me native! to the core.
<snip>
> I did not look at their approach too long but I think
> they are passing some parameters to the cgi message
> that are then echoed back on the response. So the
> original posting message already knows the logo, and
> possible error or success messages.
This was my take on the code. It seems to be a way to use a centralized,
non-brand specific system, where branding can then be used to personalize
the response.
> For example, you can change the success message
> to "has, we think, really been sent to:"
I would prefer a message something like, "If the sun spots are not too
bright and you *have* paid your bill, then the message has gone through."
;-)
By the way, the "person" that lives at 416-555-1212 is really fascinating!
;-)
> I think this is clever ... allowing you to control some output on the
> response page and make your parsing work easier.
> And making you a bit more independent of changes to the processing
program.
It is clever. First, I've specifically noted, but I have little doubt that
there are more out there.
<snip>
End of my irrelevant comments, except to acknowledge that I was not paying
close attention to the messages. Sorry!! (Scott gracefully exits stage
left)
--Scott Jones
[10/10] from: kimm2:mcmaster:ca at: 10-Jun-2002 11:14
Thanks everyone for you help!
Scott, I couldn't quite get yours to work due to my lack of REBOL/HTML
know how.
Cybarite, your solution worked perfectly, just copied and pasted (a load
off my shoulder!).
Thanks again! I'm sure I'll be needing your guys' help in the near
future. :)
Cheers,
Matt
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted