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

HTTP Post Not working

We are trying to implement the HTTP POST request on the ROKU but it is not working giving us the HTTP 405 error, but we are posting the data with the method PostFromString("").

Please Find the Code Snippet


timeout% = 1500
roRequest = CreateObject("roURLTransfer")
roRequest.setUrl("http://httpbin.org/post")

roPort = CreateObject("roMessagePort")
roRequest.setPort(roPort)
roRequest.PostFromString("Please Work ")
sleep(1000)

if (roRequest.AsyncGetToString())
roEvent = wait(timeout%, roRequest.GetPort())
print roEvent
if type(roEvent) = "roUrlEvent"
str = roEvent.GetString()
print "i am here"
print roEvent.GetResponseCode()
print str
else if roEvent = invalid
roRequest.AsyncCancel()
REM reset the connection on timeouts
print "Unknown"
else
print "roUrlTransfer::AsyncGetToString(): unknown event"
endif
endif





Thanks In Advance.
Bhushan
0 Kudos
4 REPLIES 4
TheEndless
Channel Surfer

Re: HTTP Post Not working

You're getting a 405 from the AsyncGetToString() call. Your PostFromString() call does the post, then discards the response (as documented here: http://sdkdocs.roku.com/display/RokuSDK ... ingrequest). I think you should remove the PostFromString() line and change the AsyncGetToString() with AsyncPostFromString("Please Work "), and you should get the result you're looking for.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
pradeeptv
Visitor

Re: HTTP Post Not working

Hello,

We tried with the suggestion provided by you but we are getting the roEvent as invalid.
Please find the code snippet below


timeout% = 1500
roRequest = CreateObject("roURLTransfer")
roRequest.setUrl("http://httpbin.org/post")
print "start from here"

roPort = CreateObject("roMessagePort")
roRequest.setPort(roPort)
print "after setting the port"
sleep(1000)

if (roRequest.AsyncPostFromString("Please Work"))
roEvent = wait(timeout%, roRequest.GetPort())
print roEvent
if type(roEvent) = "roUrlEvent"
str = roEvent.GetString()
print "i am here"
print roEvent.GetResponseCode()
print str
else if roEvent = invalid
roRequest.AsyncCancel()
REM reset the connection on timeouts
print "Unknown"
else
print "roUrlTransfer::AsyncGetToString(): unknown event"
endif
endif

0 Kudos
renojim
Community Streaming Expert

Re: HTTP Post Not working

Your code works for me. You might want to try a timeout of 0 (zero). You'll get an invalid event if the timeout occurs before the async transfer completes.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
pradeeptv
Visitor

Re: HTTP Post Not working

Thanks! It's working
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.