User bio
404 bio not found
Member since Mar 12, 2024
Posts:
Ludwig has not published any posts yet.
Replies:

Hi Nezla,

Unfortunately, I don't know if it's possible to achieve what you want by using %Net.HttpRequest. 
If the data is that simple, I'd probably try and handle the HTTP communication manually over TCP.

Please be aware that this is just a quick code snippet, and you'll probably need to refine it further to suit your needs. In the open command you can alter /KEEPALIVE=n to keep the connection alive for n seconds where n>30 and n<432000

randomFunction
 new device,buffer,key,val,iterator
 new url,endpoint,http,headers
 
 set url="stream.wikimedia.org"
 set endpoint="/v2/stream/recentchange"
 set headers = {}
 do headers.%Set("Accept","*/*")
 do headers.%Set("Host",url)
 do headers.%Set("User-Agent","TestClient")
 
 set device="|TCP|2"
 open device:(/HOSTNAME="185.15.59.224":/PORT=443:/SSL="test":/STREAM=1:/KEEPALIVE=30):5
 if $test=0 {
    write "- Failed to connect"
    close device
    quit
 }
 
 use device
 
 write "GET "_endpoint_" HTTP/1.0"_$c(13,10),*-3
 set (key,value,type)=""
 set iterator=headers.%GetIterator()
 while iterator.%GetNext(.key,.value,) {
    write key_":"_value_$c(13,10),*-3
 }
 write $c(13,10,13,10),*-3
 // Ignore first message
 read buffer:5
 if $test=0 {
    use 0
    write "- Failed to read anything",!
    zw buffer
    close device
    quit
 }
 
 // Write ":ok" so API begins sending data
 write ":ok"_$c(13,10)
 
 read buffer:5
 use 0
 if $test=0 {
    use 0
    write "- Failed to read anything",!
    zw buffer
    close device
    quit
 }
 
 use 0
 zw buffer
 close device
 quit
 ;

Best regards
Ludwig

Hi Fahima,

Perhaps something along these lines will be useful to you (Note: You need to add some more checks, but you get the gist) 

 set status=##class(%XML.TextReader).ParseFile(<filepath>,.textreader)
 do textreader.ReadStartElement("content")
 
 while textreader.Read() {
	if (textreader.NodeType="endelement")&&(textreader.Name="content") {
		quit
	}
	
	// Handle values of content element here
 }
Certifications & Credly badges:
Ludwig has no Certifications & Credly badges yet.
Global Masters badges:
Followers:
Ludwig has no followers yet.
Following:
Ludwig has not followed anybody yet.