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: 
squirreltown
Roku Guru

Header

Come on some one help me out here. Is there something obviously wrong with this line?
urlobj.AddHeader("Content-Type" , "application/x-www-form-urlencoded")  

will the roku not send this header for some reason??
thanks
Kinetics Screensavers
0 Kudos
8 REPLIES 8
RokuChris
Roku Employee
Roku Employee

Re: Header

There is nothing obviously wrong with that line. I often send content-type headers with requests, so I know it's possible.

Are you 100% sure it's not being sent? Have you tried adding other headers to a request to see if those work?
0 Kudos
squirreltown
Roku Guru

Re: Header

Thank You Chris. I am adding it to the function below (from url.brs) and reading the response from a header echo URL Mark supplied.
If i give "Expect" a value of "100-continue" it echos back, with no value (as below) it doesn't.
If I add the header "Accept" (over-riding the internal Roku-added header) and make the value "application/x-www-form-urlencoded" it echos back. (the roku value is normally */*) .
Neither of these will echo
 urlobj.AddHeader("Content-Type","application/x-www-form-urlencoded")
urlobj.AddHeader("Content-Length", "0")


I can't see any reason why its not coming back, or being added.


Function http_prep(method="" As String)
' this callback allows just-before-send
' mods to the request, e.g. timestamp
if isfunc(m.callbackPrep) then m.callbackPrep()
m.status = 0
m.response = ""
urlobj = CreateObject("roUrlTransfer")
if type(m.port)<>"roMessagePort" then m.port = CreateObject("roMessagePort")
urlobj.SetPort(m.port)
urlobj.SetCertificatesFile("common:/certs/ca-bundle.crt")
urlobj.EnableEncodings(true)
urlobj.AddHeader("Expect","")
urlobj.AddHeader("Content-Type","application/x-www-form-urlencoded") ''''
urlobj.AddHeader("Content-Length", "0") ''''
url = m.GetUrl()
urlobj.SetUrl(url)
if m.method<>"" and m.method<>method then urlobj.SetRequest(m.method)
HttpActive().replace(m,urlobj)
m.timer.mark()
End Function
Kinetics Screensavers
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Header

Not familiar with the echo server piece. But are you sure the headers aren't being sent? Is it possible the server just isn't showing them to you for some reason?

If I put a simple 1-line PHP script on a sever on my local network:

var_dump(getallheaders());


Then do something basic in BRS like this:

  xfer = CreateObject("roURLTransfer")
xfer.SetURL("http://192.168.1.105/echo.php")
xfer.AddHeader("Content-Type","application/x-www-form-urlencoded")
xfer.AddHeader("Content-Length", "0")
? xfer.GetToString()


I see both headers on the console:

array(5) {
["User-Agent"]=>
string(28) "Roku/DVP-5.2 (065.02E05040A)"
["Host"]=>
string(13) "192.168.1.105"
["Accept"]=>
string(3) "*/*"
["Content-Type"]=>
string(33) "application/x-www-form-urlencoded"
["Content-Length"]=>
string(1) "0"
}
0 Kudos
squirreltown
Roku Guru

Re: Header

Thanks for the effort Chris, I will try to duplicate what you've done and report what happens. I'm guessing the PHP script will react the same on my website, I don't have a local server.
I have no idea about the echo URL, its something RokuMarkn wrote and made available. I have considered that it might not read everything but it seems unlikely to write something that way, but i really don't know.
Kinetics Screensavers
0 Kudos
RokuMarkn
Visitor

Re: Header

Hey Chris, you want to direct your query to my site to make sure that's not the problem? I haven't used mine much but it's very simple, similar to yours but in perl. It's possible perl filters out some headers but I don't think so. Mine is greenwoodsoftware.com/cgi-bin/echo-headers

--Mark
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Header

"RokuMarkn" wrote:
Hey Chris, you want to direct your query to my site to make sure that's not the problem? I haven't used mine much but it's very simple, similar to yours but in perl. It's possible perl filters out some headers but I don't think so. Mine is greenwoodsoftware.com/cgi-bin/echo-headers


Can do. The exact same code with just the URL changed gives this:

ACCEPT: */*
USER-AGENT: Roku/DVP-5.2 (065.02E05040A)
HOST: greenwoodsoftware.com
0 Kudos
squirreltown
Roku Guru

Re: Header

ACCEPT-ENCODING: deflate, gzip
ACCEPT: */*
USER-AGENT: Roku/DVP-5.1 (025.01E01195A)
HOST: greenwoodsoftware.com


Thats what I'm getting. So it IS filtering those out. Right??
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: Header

So here it is, they are all going out.
{
"form": {},
"headers": {
"Content-Length": "0",
"Accept-Encoding": "deflate, gzip",
"Accept": "*/*",
"Connection": "close",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Roku/DVP-5.1 (025.01E01195A)",
"Host": "httpbin.org"
},
"data": "",
"url": "http://httpbin.org/post",
"origin": "75.163.7.76",
"json": null,
"files": {},
"args": {}
}

Thanks Chris & mark
Kinetics Screensavers
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.