Brad Cypert
Brad Cypert

Reputation: 679

Getting Premature end of file when building an XML object from a URL

I'm trying to run the following code val podcastXml = XML.load(new URL(feed)) where the feed in question is https://fourfingerdiscount.podbean.com/feed/

I'm able to load the feed in my browser fine, but I'm getting an error: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of file. when I try to run that code against it.

Interestingly enough, when I try to curl the feed URL in my browser, it's empty.

Any idea what I'm doing wrong here? I feel like there's a config option that I'm somehow missing.

Also worth mentioning, some of the feeds work fine such as http://maximumfun.org/feeds/are.xml

Upvotes: 1

Views: 612

Answers (1)

Antot
Antot

Reputation: 3964

Reading from HTTPS URLs is not so straight as with this new URL(feed). It doesn't get the desired XML contents so easily, but rather an empty response and so the SAXParseException.

However the data can be retrieved, one of the ways is the old HttpsUrlConnection. But there are also a number of wrapper libs allowing to facilitate it, for example scalaj-http. With it, you can proceed as follows:

import scalaj.http.Http

val url = "https://fourfingerdiscount.podbean.com/feed/"
val xml = Http(url).execute(XML.load).body
// xml is a parsed scala.xml.Elem with the contents you were looking for

Upvotes: 2

Related Questions