
squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2013
12:58 PM
Http headers
I am getting a http 400 error for what appears to be a valid request to Twitter. In the docs for URLtransfer is the following:
What exactly are the headers that are automatically sent?
thanks
"Certain well known headers such as User-Agent, Content-Length, etc. will automatically be sent. The application may override these well known values if needed (e.g. some servers may require a specific user agent string)."
What exactly are the headers that are automatically sent?
thanks
Kinetics Screensavers
6 REPLIES 6

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2013
03:20 PM
Re: Http headers
The best way to verify exactly what headers you're sending is to send the request to a header echo server. There are a variety of such servers around; they will respond to a request with a copy of the headers that were sent to it. So change your script to temporarily send your query to that server instead of to the twitter server, and read the response to see what headers were sent. Here's a simple one that I wrote; feel free to use it: http://greenwoodsoftware.com/cgi-bin/echo-headers
--Mark
--Mark

squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013
06:51 AM
Re: Http headers
Thank you Mark, I'll give it a try.
Kinetics Screensavers

squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013
10:01 AM
Re: Http headers
OK not able to get any response in the debugger other than what i had before. Is this the right way to listen?
Alos where do I need to listen? Here? the tweet function is being called from a button on a canvas. Do i need to add a while loop in the NewHttp function? Also, my channel already has an m.port, but it seems like NewHttp is creating one too. Does the Roku allow 2 m.ports or does it know they are the same?
thanks
oa = Oauth()
'http = NewHttp("https://api.twitter.com/1.1/statuses/update.json","" ,"POST")
http = NewHttp("http://greenwoodsoftware.com/cgi-bin/echo-headers","" ,"POST")
oa.sign(http,true)
http.PostFromStringWithTimeout( "", 10 )
while(true)
msg = wait(100,m.port)
if type(msg) = "roUrlEvent"
str = msg.GetString()
print str
exit while
end if
end while
Alos where do I need to listen? Here? the tweet function is being called from a button on a canvas. Do i need to add a while loop in the NewHttp function? Also, my channel already has an m.port, but it seems like NewHttp is creating one too. Does the Roku allow 2 m.ports or does it know they are the same?
thanks
Kinetics Screensavers


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013
11:03 AM
Re: Http headers
PostFromStringWithTimeout() has it's own event loop and returns the response as a string. You don't need a second event loop. Yours is probably never getting a roUrlEvent because it's being caught by the one in PostFromStringWithTimeout().

squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013
11:21 AM
Re: Http headers
Ok thanks Chris, You answered a question for me last week where you pointed out that the PostFromStringWithTimeout I was using was not the SDK one, but a different one in url.brs. As you see below there doesnt appear to be a loop here? (or in http_prep)
So that takes me back to the problem of not getting the headers back from that URL Mark supplied, which works fine in a browser. If i just change the URL from twitter to Mark's I only get the Http code response which is 400 from twitter and from Mark is 200. Where should i listen to get the whole thing with headers? Frankly I am not overly interested in the headers but I know the people on the Twitter developer board will be which is where i need to go with my bad request problem.
Thanks
EDIT:
I think i found it, i needed to listen in -- Function http_wait_with_timeout(seconds As Integer) As Boolean. I got some headers back this time but not what i was expecting
At least moves the ball forward a little. Thanks again Chris.
Function http_post_from_string_with_timeout(val As String, seconds as Integer) as String
m.Prep("POST")
if (m.Http.AsyncPostFromString(val)) then m.Wait(seconds)
return m.response
End Function
So that takes me back to the problem of not getting the headers back from that URL Mark supplied, which works fine in a browser. If i just change the URL from twitter to Mark's I only get the Http code response which is 400 from twitter and from Mark is 200. Where should i listen to get the whole thing with headers? Frankly I am not overly interested in the headers but I know the people on the Twitter developer board will be which is where i need to go with my bad request problem.
Thanks
EDIT:
I think i found it, i needed to listen in -- Function http_wait_with_timeout(seconds As Integer) As Boolean. I got some headers back this time but not what i was expecting
ACCEPT-ENCODING: deflate, gzip
ACCEPT: */*
USER-AGENT: Roku/DVP-5.1 (025.01E01195A)
HOST: greenwoodsoftware.com
At least moves the ball forward a little. Thanks again Chris.
Kinetics Screensavers

squirreltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2013
12:11 PM
Re: Http headers
One more thing, I am now trying to add headers. The function below has this"
urlobj.AddHeader("Expect","")but its not showing in the echo headers I'm getting. Is the function not sending it or is the echo not returning it because it has no value? I tried adding a couple others but they dont show either.
ACCEPT-ENCODING: deflate, gzip
ACCEPT: */*
USER-AGENT: Roku/DVP-5.1 (025.01E01195A)
HOST: greenwoodsoftware.com
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