home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 May / PCO_5_97.ISO / FilesBBS / OS2 / OS2WWW42.ARJ / OS2WWW42 / OS2WWW42.ZIP / SYS402.R4 / BIN / CALLHTTP.CMD < prev    next >
Encoding:
Text File  |  1996-08-18  |  2.2 KB  |  99 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.  
  5.     Arguments:
  6.         http        =    the command string to send
  7.         user        =    name of a user with admin privileges
  8.         password    =    password for that user
  9.         begin_at    =    the string to look for before echoing the response
  10.         end_at    =    the string to look for to stop echoing the response
  11.     --------------------------------------------------------------------    */
  12.  
  13. http         = arg(1)
  14. user        = arg(2) 
  15. password    = arg(3)
  16. begin_at    = arg(4)
  17. end_at    = arg(5)
  18.  
  19. call RxFuncAdd 'SysTempFileName', 'RexxUtil', 'SysTempFileName'
  20. call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  21.  
  22. /* Submit the request, capturing output to a temporary file. */
  23.  
  24. filename = SysTempFileName("h?????.rsp")
  25.  
  26. if length(user) > 0 then
  27.     '@submit "'http'" -u'user':'password' >'filename '2>&1'
  28. else
  29.     '@submit "'http'" >'filename
  30.  
  31. /* Read the response and extract only the relevant portion. */
  32.  
  33. begun = 0
  34. ended = 0
  35. doall = 0
  36. inhdr = 1
  37.  
  38. call stream filename, 'C', 'open read'
  39.  
  40. /* The first line should always be an HTTP response */
  41.  
  42. response = linein(filename)
  43. if pos("HTTP/", response) != 1 then do
  44.     doall = 1
  45.     say response
  46. end
  47. else do
  48.     parse value response with protocol status message
  49.  
  50.     if \(status = 200) then do
  51.         say message
  52.         return
  53.     end
  54. end
  55.  
  56. do while \ended & lines(filename)
  57.     response = linein(filename)
  58.  
  59.     if length(response) = 0 then do
  60.         inhdr = 0
  61.         if length(begin_at) = 0 then
  62.             begun = 1
  63.  
  64.         if \doall then
  65.             iterate
  66.     end
  67.  
  68.     if doall then
  69.         say response
  70.     else if begun then do
  71.         if pos(end_at, response) > 0 then
  72.             ended = 1
  73.         else do 
  74.  
  75.             /* remove the HTML markup tags */
  76.             answer = ''
  77.             do while length(response) > 0
  78.                 parse value response with keep '<' discard '>' response
  79.                 answer = answer keep
  80.             end
  81.  
  82.             /* echo the response from the server to the console */
  83.             say strip(answer)
  84.         end
  85.     end
  86.     else if pos(begin_at, response) > 0 then do
  87.         begun = 1
  88.     end
  89. end
  90.  
  91. /* Remove the file containing the response. */
  92.  
  93. call stream filename, 'C', 'close'
  94. call SysFileDelete filename
  95.  
  96. return
  97.  
  98.  
  99.