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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do i recreate a html request header?

I'm currently writing a Java Application that remotely controls my Roku. I found this website and used it to control my Roku. From Chromes developer tools i watched its data traffic and found the html request that controlled the Roku. The Header was this.

POST /keydown/Play HTTP/1.1
Connection: keep-alive
Content-Length: 0
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
I then tried to recreate this POST request within Java and it ended up looking like this:

HttpURLConnection urlConn;
URL url = new URL("html://");
urlConn = (HttpURLConnection) url.openConnection();

urlConn.setRequestProperty("Connection", "keep-alive");
urlConn.setRequestProperty("Content-Length", "0");
urlConn.setRequestProperty("Cache-Control", "max-age=0");
urlConn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
urlConn.setRequestProperty("Origin", "");
urlConn.setRequestProperty("Upgrade-Insecure-Requests", "1");
urlConn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36");
urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
urlConn.setRequestProperty("Referer", "");
urlConn.setRequestProperty("Accept-Encoding", "gzip, deflate");
urlConn.setRequestProperty("Accept-Language", "en-US,en;q=0.8");
I'm not 100% sure this is the correct way to recreate the request because it does not have the same effect as the the original (working). However, this may be because I changed a few minor details that may have actually be important. So my question to you is if this the correct way to recreate a request and if it is why is it not working? If not what is? Any help is appreciated
0 Kudos
Roku Guru

Re: How do i recreate a html request header?

I'd post this in the Developer's forum instead.
Yeah, I got some Rokus.
0 Kudos
Roku Guru

Re: How do i recreate a html request header?

Most of those properties you're setting are unnecessary. The one thing you do need that you're missing is setRequestMethod("POST"). I don't do Java, so there may be other issues with your code.

Also, instead of using Chrome Developer Tools to determine the Roku interface, why not read the documentation:
0 Kudos

Re: How do i recreate a html request header?

I agree with belltown.
Java Developer
0 Kudos
Binge Watcher

Re: How do i recreate a html request header?

Roku also has a bunch of free tools here -
RemoteRoku is the first on the left, Deeplinker allows you to add fields in addition to contentID and Mediatype too.
I don't think their tools allow much interaction (if any) with customizing headers in requests there, but they shouldn't be needed except for perhaps the video playback tester tool, which includes a headers tab.
As for creating a header in the channel app, use AddHeader
0 Kudos
Roku Guru

Re: How do i recreate a html request header?

If you set on using chromes developer tools, may I suggest right clicking on the data you are referring to and "copy as curl"
0 Kudos