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: 
jamesmason
Visitor

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
Host: 192.xxx.x.82:8060
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
Origin: http://remoku.tv
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
Referer: http://remoku.tv/
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://192.xxx.x.82:8060/keydown/Play");
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", "http://192.xxx.x.254");
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", "http://192.xxx.x.254");
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
5 REPLIES 5
jeffrok
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.
https://youtu.be/d1CSEeqWl10
0 Kudos
belltown
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: https://sdkdocs.roku.com/display/sdkdoc/External+Control+API
0 Kudos

Re: How do i recreate a html request header?

I agree with belltown.
Java Developer
0 Kudos
destruk
Streaming Star

Re: How do i recreate a html request header?

Roku also has a bunch of free tools here - http://devtools.web.roku.com/
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
norcaljohnny
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
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.