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

[REBOL] HTTP-Post Error

From: mattymattkim::hotmail::com at: 17-Oct-2002 0:27

I'm using the HTTP-POST script found on the REBOL website to send SMS messages over Rogers AT&T's website. http://www.rogers.com/english/wireless/sendpcs.html It's been working beautifully in the past with some help from you REBOL genious' but now occasionally I seem to get a "HTTP/1.1 500 Internal Server Error". Is Rogers trying to throttle the amount of SMS messages sent by 1 user through their website? Is there any way around this? Here's my modified code (warning, it's very crude!). I think most of it's the same as the original, except the bottom. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ REBOL [ Title: "Simple HTTP POST" File: %http-post.r Author: "Martin Johannesson" Email: [d95-mjo--nada--kth--se] Date: 30-Jun-1999 Purpose: { This script sends a "form" to a webserver using the POST method. The included example translates a string in English to German by posting the data to AltaVista's translation web page and then parsing the reply. } Category: [web util net 4] ] url-encode: func [ {URL-encode a string} data "String to encode" /local new-data ][ new-data: make string! "" normal-char: charset [ #"A" - #"Z" #"a" - #"z" #"@" #"." #"*" #"-" #"_" #"0" - #"9" ] if not string? data [return new-data] forall data [ append new-data either find normal-char first data [ first data ][ rejoin ["%" to-string skip tail (to-hex to-integer first data) -2] ] ] new-data ] http-post-form: func [ {Post a form to a web server} url "The URL to post to" data [block!] "A block of name/value pairs to represent the form" /local encoded-data port-spec HTTP-Post-Header http-request buffer tmp-buffer ][ port-spec: make port! [ scheme: 'tcp port-id: 80 timeout: 0:10 ] net-utils/url-parser/parse-url port-spec url encoded-data: make string! "" foreach [name value] data [ append encoded-data rejoin [ url-encode name "=" url-encode value "&" ] ] remove back tail encoded-data HTTP-Post-Header: make object! [ Accept: "*/*" User-Agent: reform ["REBOL" system/version] Host: port-spec/host Content-Type: "application/x-www-form-urlencoded" Content-Length: length? encoded-data ] http-request: rejoin [ "POST /" either found? port-spec/path [port-spec/path][""] either found? port-spec/target [port-spec/target][""] " HTTP/1.0^/" net-utils/export HTTP-Post-Header "^/" encoded-data ] http-port: open/lines [ scheme: 'tcp port-id: port-spec/port-id timeout: port-spec/timeout host: port-spec/host user: port-spec/user pass: port-spec/pass ] insert http-port http-request buffer: make string! 10000 tmp-buffer: reform ["HTTP-Response:" pick http-port 1] while [not none? tmp-buffer] [ append buffer rejoin [tmp-buffer "^/"] tmp-buffer: pick http-port 1 ] close http-port HTTP-Header: make object! [ HTTP-Response: Date: Server: Last-Modified: none Accept-Ranges: Content-Encoding: Content-Type: none Content-Length: Location: Expires: Referer: Connection: none ] parse-header HTTP-Header buffer ] 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" ; ] ] ;'area' 'number' and 'textbody' are variables loaded from another function. ;ex. '416' '5551234' 'hello there' print send-message area number textbody _________________________________________________________________ Surf the Web without missing calls! Get MSN Broadband. http://resourcecenter.msn.com/access/plans/freeactivation.asp