roURLTranfer returning response code -1 (CURLE_UNSUPPORTED_PROTOCOL)

I have this simple usage of roURLTransfer:

    xfer = CreateObject("roURLTransfer")
    xfer.SetPort(port)
    xfer.SetCertificatesFile("common:/certs/ca-bundle.crt")
    xfer.SetURL(url)
    if xfer.AsyncGetToString()
        event = wait(timeout, port)
        if type(event) = "roUrlEvent"
            m.responseCode = event.GetResponseCode()
            print "request took: " + timer.TotalMilliseconds().ToStr()
            print "response code: " + m.responseCode.ToStr()
            result = event.GetString()
        endif
    end if

The URL is an https:// URL and works fine in browser and other tools. On roku, the response code is always -1, the request only takes about 200ms, and the response is always blank. According to the documentation https://developer.roku.com/docs/references/brightscript/events/rourlevent.md#getresponsecode-as-integer the code means that cURL doesn’t support the protocol. I don’t understand this at all. Can somebody please advise?

Update: After many many hours of debugging and wishing that I hadn’t accepted this project, I determined that this is a bug with Brightscript or Roku SDK or Roku’s implementation of cUrl.

Hard to say the exact cause but the way fixed it is that I noticed that even though the content-type header specified utf-8 and the xml charset was utf-8, the HTTP responses for some reason had a BOM marker (specifically UTF-8’s xEF xBB xBF). After removing that all the requests started processing correctly.

This is a very frustrating bug as the error reported is incorrect and further information is not available.