How to get a textfile returned from URL

I am trying to get some data provided by the National Weather Service. Unfortunately, this particular website does not embed the data in the html that is returned from a URL request. Instead they initiate a download of the data to the local machine as a text file. Fine, I can read that file. But I’m having trouble automating this with XOJO.

Idea 1: Using the URLConnection.Send(“GET”, URL) method does not work because the data is not contained in the returned html. And this does not imitate the file download.

Idea 2: Using the WebViewer. But XOJO takes the file destined to be downloaded and displays it in the viewer. And I can’t seem to programmatically get at what is displayed there (I think this is for security reasons). I can copy and paste it manually but that isn’t what I want.

So I’m stumped at how to get this data. I searched for and found some 3 year old posts on using javascript for this. Is that still the best or only way? I know javascript somewhat but have never implemented this with XOJO.

A sample of what I am after can be generated with the following url. Try this first in the browser of your choice and you’ll see the resulting text file I’m after.

https://www.weather.gov/mdl/nbm_text?ele=nbs&sta=kmry,kpdx&download=yes

Any help would be appreciated. Thx

You should use their API, which is documented here, to get the JSON data you need.

Just as a quick test, I hit their active alerts end-point which is documented here using the following code with a URLConnection object on a window and I get a valid JSON response in the ContentReceived event:

NWSConnect.RequestHeader( "User-Agent" ) = "(weathertestapp, email@example.com)"
NWSConnect.RequestHeader( "Accept" ) = "application/ld+json"
NWSConnect.Send( "GET", "https://api.weather.gov/alerts/active" )

Thank you. I’ll investigate that method.

Unfortunately, their API does not appear to provide access to the weather product I’m after.

Another idea I had was to launch a separate browser application with the URL I’m after. That will cause the file to download where I can detect it and upload. Seems a round about way to do this but might work.