home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 November / PCO_1198.ISO / filesbbs / os2 / os2www.arj / OS2WWW.ZIP / SYS406.R8 / BIN / CALLHTTP.CMD < prev    next >
Encoding:
Text File  |  1997-03-21  |  3.0 KB  |  128 lines

  1. /* --------------------------------------------------------------------
  2.     Call the HTTP submit program to send a request to the local server.
  3.     This is not a stand-alone program, it is to be used as a subroutine.
  4.     First attempts to connect with HTTPS and, if fails, falls back to HTTP.
  5.  
  6.     Arguments:
  7.         http        =    the command string to send
  8.         user        =    name of a user with admin privileges
  9.         password    =    password for that user
  10.         begin_at    =    the string to look for before echoing the response
  11.         end_at    =    the string to look for to stop echoing the response
  12.     --------------------------------------------------------------------    */
  13.  
  14. http         = arg(1)
  15. user        = arg(2) 
  16. password    = arg(3)
  17. begin_at    = arg(4)
  18. end_at    = arg(5)
  19.  
  20. call RxFuncAdd 'SysTempFileName', 'RexxUtil', 'SysTempFileName'
  21. call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  22.  
  23. /* Submit the request, capturing output to a temporary file. */
  24.  
  25. filename = SysTempFileName("h?????.rsp")
  26. retries    = 0
  27.  
  28. do    until \((rc = 3) & (retries < 5))
  29.     if length(user) > 0 then
  30.         '@submit "'http'" -p443 -u'user':'password' >'filename '2>&1'
  31.     else
  32.         '@submit "'http'" -p443 >'filename
  33.  
  34.     if (rc = 3) | (rc = 403) then do
  35.         if length(user) > 0 then
  36.             '@submit "'http'" -u'user':'password' >'filename '2>&1'
  37.         else
  38.             '@submit "'http'" >'filename
  39.     end
  40.  
  41.     retries = retries+1
  42. end
  43.  
  44. /* Read the response and extract only the relevant portion. */
  45.  
  46. begun = 0
  47. ended = 0
  48. doall = 0
  49. inhdr = 1
  50.  
  51. call stream filename, 'C', 'open read'
  52.  
  53. /* The first line should always be an HTTP response */
  54.  
  55. response = linein(filename)
  56. if pos("HTTP/", response) != 1 then do
  57.     doall = 1
  58.     say response
  59. end
  60. else do
  61.     parse value response with protocol status message
  62.  
  63.     if \(status = 200) then do
  64.         say message
  65.         call stream filename, 'C', 'close'
  66.         call SysFileDelete filename
  67.         return
  68.     end
  69. end
  70.  
  71. do while \ended & lines(filename)
  72.     response = linein(filename)
  73.  
  74.     if length(response) = 0 then do
  75.         inhdr = 0
  76.         if length(begin_at) = 0 then
  77.             begun = 1
  78.  
  79.         if \doall then
  80.             iterate
  81.     end
  82.  
  83.     if doall then
  84.         say response
  85.     else if begun then do
  86.         if pos(end_at, response) > 0 then
  87.             ended = 1
  88.         else do 
  89.  
  90.             /* remove the HTML markup tags */
  91.             answer = ''
  92.             do while length(response) > 0
  93.                 parse value response with keep '<' discard '>' response
  94.                 answer = answer keep
  95.             end
  96.  
  97.             /* substitute common chars */
  98.  
  99.             do while pos("&", answer) > 0
  100.                 loc = pos("&", answer);
  101.                 answer = delstr(answer, loc, 5);
  102.                 answer = insert("&", answer, loc);
  103.             end
  104.  
  105.             do while pos(" ", answer) > 0
  106.                 loc = pos(" ", answer);
  107.                 answer = delstr(answer, loc, 6);
  108.                 answer = insert(" ", answer, loc);
  109.             end
  110.  
  111.             /* echo the response from the server to the console */
  112.             say strip(answer)
  113.         end
  114.     end
  115.     else if pos(begin_at, response) > 0 then do
  116.         begun = 1
  117.     end
  118. end
  119.  
  120. /* Remove the file containing the response. */
  121.  
  122. call stream filename, 'C', 'close'
  123. call SysFileDelete filename
  124.  
  125. return
  126.  
  127.  
  128.