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

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.

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

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

Thanks! It’s working