Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HTML -> CURL -> MUMPS

145 views
Skip to first unread message

Ben Irwin

unread,
Apr 4, 2013, 8:47:01 PM4/4/13
to
I have been using CURL functionality to maintain and automatically up the wbvista.info site and wanted to share some of the information.

The following is a very simple method to read a web page and place the response in a MUMPS local array.

The following routine, WBCURL, accepts a URL and the local array as input. It then makes a external function call to retrieve the web page in silent mode and store the page to a file. Once the file is stored, it is imported and placed in the local array and displayed. Simple.

WBCURL(URL,Result)
New Request,Outfile,line,count
Set Outfile="temp"_$I(^WBCURL)_".txt"
Set Request="curl -s -o "_Outfile_" "_URL
ZSYSTEM Request
;
Open Outfile:(readonly)
For Use Outfile Read line Quit:$zeof Do
. Set line=$Translate(line,$C(13),"")
. Set Result($I(count))=line
Close Outfile
;
Quit
;
TEST
New URL,TEMP
Set URL="http://wbvista.info/VDOCS/Dictionary2/D5.php"
Do WBCURL(URL,.TEMP)
ZWR TEMP
Quit

Sam Habiel

unread,
May 22, 2013, 3:49:12 PM5/22/13
to
I wrote this using PIPEs. This does posts; but you can also do gets very similarly.

CURL(RETURN,URL,PAYLOAD,MIME) ; Post using CURL
;
; Write payload to File in shared memory
N F S F="/dev/shm/"_$R(987987234)_$J_".DAT"
O F:(NEWVERSION) U F
I $D(PAYLOAD)#2 W PAYLOAD,!
F I=0:0 S I=$O(PAYLOAD(I)) Q:'I W PAYLOAD(I),!
C F
;
; Flags: -s : Silent; -X: HTTP POST; -k : Ignore certificate validation.
N CMD S CMD="curl -s -XPOST -k "_URL_" --header 'Content-Type:"_MIME_"'"_" --da
ta-binary @"_F
;
; Execute and read back
N D S D="cURLDevice"
O D:(shell="/bin/sh":command=CMD)::"PIPE" U D
F I=1:1 R RETURN(I)#4000:1 Q:$ZEOF K:RETURN(I)="" RETURN(I)
K:RETURN(I)="" RETURN(I)
C D
;
O F
C F:(DELETE)
;
QUIT
0 new messages