Created
May 23, 2018 00:30
-
-
Save mainframed/d194985a6c0de0d572a975b4a5b03cfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* REXX */ | |
/* Simple HTTP REXX CURL */ | |
/* Usage: HTTPR 'URL' or HTTPR '-O DATASET URL' */ | |
/* Arguments: -O output to a file */ | |
/* URL site to get */ | |
/* By default the script will display the contents of the URL to the screen */ | |
/* Cribbed from: */ | |
/* https://groups.google.com/forum/#!topic/bit.listserv.tsorexx/lk74hblwn3U */ | |
/* Copyright Soldier of FORTRAN */ | |
/* trace i */ | |
PARSE ARG URL | |
if length(url) == 0 then do | |
SAY "Usage: HTTPR (-O FILENAME) <URL>" | |
Return -1 | |
end | |
verbose = 0 | |
SAVE = 0 | |
if POS('-O', URL) > 0 THEN DO | |
PARSE VAR URL . FILENAME URL | |
SAVE = 1 | |
if verbose then say "Saving to File:" FILENAME | |
END | |
if POS('HTTP',translate(url)) > 0 then | |
PARSE VALUE URL WITH SCHEME "://" HOST "/" PATH | |
else do | |
PARSE VALUE URL WITH HOST "/" PATH | |
SCHEME = HTTP | |
end | |
IF (TRANSLATE(SCHEME) == 'HTTPS') THEN DO | |
SAY 'HTTPS NOT SUPPORTED' | |
RETURN -1 | |
END | |
/* Get the Site */ | |
LENGTH = 0 | |
CRLF = '0D25'x | |
srv = Socket('Initialize', 'wget') | |
srv = Socket('Socket') | |
parse var srv src ssockid | |
srv = Socket('Gethostbyname',HOST); parse var srv src serverip | |
if src > 0 then | |
serverip = HOST | |
srv = Socket('Setsockopt',ssockid,'SOL_SOCKET','SO_REUSEADDR','ON') | |
srv = Socket('Setsockopt',ssockid,'SOL_SOCKET','SO_LINGER','OFF') | |
srv = Socket('Setsockopt',ssockid,'SOL_SOCKET','SO_ASCII','ON') | |
srv = Socket('Connect',ssockid,'AF_INET' 80 serverip) | |
parse var srv src | |
If src > 0 | |
then do | |
Say 'Connect to' HOST 'returned' srv | |
Say 'Error: Aborting process' | |
Return | |
End | |
IF VERBOSE THEN DO | |
Say ' ' | |
Say 'Connected to server' HOST 'ip='serverip 'port='80 | |
say 'Sending HTTP request for' PATH | |
say ' ' | |
END | |
httpget = 'GET' '/'PATH 'HTTP/1.0' CRLF | |
srv = Socket('Send',ssockid,httpget) | |
parse var srv src len | |
hosttxt = 'Host:' HOST':80' CRLF | |
parse var srv src len | |
srv = Socket('Send',ssockid,hosttxt) | |
srv = Socket('Send',ssockid,CRLF) | |
srv = Socket('Recv',ssockid) | |
parse var srv src len data | |
i = 0 | |
parse var data headers '0D250D25'x content | |
do until (headers == '') | |
i = i + 1 | |
parse var headers h.i '0D25'x headers | |
end | |
h.0 = i | |
DO x = 1 TO h.0 | |
if verbose then say h.x | |
if WORDPOS('Content-Length:', h.x) > 0 then | |
parse var h.x . length | |
end | |
if verbose then say '' | |
DO WHILE length(content) < length | |
srv = Socket('Recv',ssockid) | |
parse var srv src len data | |
if len == 0 then do | |
say "error cannot retrieve more data" | |
say src data | |
end | |
else do | |
content = content||data | |
end | |
end | |
i = 0 | |
do until (content == '') | |
i = i + 1 | |
parse var content c.i '25'x content | |
end | |
c.0 = i | |
if save then do | |
"ALLOCATE DA('"FILENAME"') F(OUTDD) MOD REUSE" | |
"EXECIO "c.0" DISKW OUTDD (FINIS STEM c." | |
"FREE F(OUTDD)" | |
if rc = 0 then | |
say c.0 "records were written to '"FILENAME"'" | |
else | |
say "Error during 1st EXECIO ... DISKW, return code is " RC | |
end | |
else do | |
do x = 1 to c.0 | |
say c.x | |
end | |
end | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment