Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
NedMobile
Reel Rookie

roUrlEvent returns "??" as body with 200 status code

I'm trying to fetch some JSON data from my server but about 60% of the time the roURLEvent returns "??" as the body of the request. The other 40% of the times it works as expected (the content response hasn't changed).

The code for the request is the following

 

function request()
    baseurl = m.top.url
    token = m.top.token
    url = baseurl + "/some_endpoint"
    ? "Task URL: ";url
    ? "Token: "; token
    http = createObject("roUrlTransfer")
    http.RetainBodyOnError(true)
    port = createObject("roMessagePort")
    http.setPort(port)
    http.setCertificatesFile("common:/certs/ca-bundle.crt")
    http.InitClientCertificates()
    http.enablehostverification(false)
    http.enablepeerverification(false)
    http.addHeader("token", token)
    http.setUrl(url)
    if http.AsyncGetToString() Then
      msg = wait(100000, port)
      if (type(msg) = "roUrlEvent")
        if (msg.getresponsecode() > 0 and  msg.getresponsecode() < 400)
          print "Task Response "
          print msg
          stop

In the debugger I print the msg headers and everything seems to be ok

{
    access-control-allow-origin: "*"
    cache-control: "max-age=10"
    connection: "keep-alive"
    content-encoding: "gzip"
    content-type: "application/json; charset=utf-8"
    date: "Thu, 03 Oct 2019 01:06:28 GMT"
    etag: "W/"474-4DPxJcE1OYaf4iQIgRkIlpu9KQA""
    transfer-encoding: "chunked"
    vary: "Accept-Encoding"
    x-powered-by: "..."
}

But everytime I print the msg.getString(), or just msg, I get "??" on the console. Also I'm pretty positive the backend is working as expected since I have 2 mobile apps running on the same server without any issues, I also double checked the url and it's the right one (since it works 40% of the time)

I'm really lost here since I don't see what could be going on. Maybe it's has to be with the encoding? but it works 40% of time so it doesn't make sense. I'm also running 2 other queries to the same server at the same time, which work mostly without issue (one of the other queries fails with the same error but only about 10% of the time)

Any ideas?

0 Kudos
2 REPLIES 2
joetesta
Roku Guru

Re: roUrlEvent returns "??" as body with 200 status code

NedMobile
Reel Rookie

Re: roUrlEvent returns "??" as body with 200 status code

I haven't tried that, honestly I wasn't even aware of what gzip was. Anyway, it seems to be working for now. I'll update after a bit more testing.

Thanks a lot for the help!