Forum Discussion

squirreltown's avatar
squirreltown
Roku Guru
12 years ago

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

8 Replies

  • 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?
  • 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
  • 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"
    }
  • 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.
  • 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
  • "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
  • 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??
  • 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