Difference between AsyncGetToString and AsyncPostFromString?

旧巷老猫 提交于 2020-01-04 05:47:28

问题


I create one web API. and I call in bright-script. I refer https://developer.roku.com/en-gb/docs/references/brightscript/interfaces/ifurltransfer.md#head-as-dynamic/ all the method but don't understand anyone knows its real use for AsyncGetToString and AsyncPostFromString method.

I use the following code in Roku

readInternet = createObject("roUrlTransfer")
      readInternet.setUrl(url)
      readInternet.setport(m.port)

      readInternet.gettostring()
      timer = createobject("roTimeSpan")
      timer.Mark()
      readInternet.AsyncPostFromString() 'readInternet.AsyncGetToString

But its every time fire Get method in My Roku Server.

here the Roku server code(using Get method)

public string Get(int id)
{
            return "The vlaue is: " + id;
}

its always call this method both the way (using Post method)

 [HttpPost] // OWIN - Open Web Interface for .NET
 public HttpResponseMessage Post([FromUri]string name, [FromUri]string pass) // Its use both FromBody (complex type from the query string) and FromUri(primitive type from the request body)
 {
      //return "UserName Details :" + name + pass;
      return Request.CreateResponse(HttpStatusCode.OK, name + " " + pass); //Using Post Method
 }

please any one help me.


回答1:


AsyncPostFromString() allows you to make an asynchronous POST request which once completed will send a message to the message port associated with it (in this case m.port).

m.port = createObject("roMessagePort")
readInternet = createObject("roUrlTransfer")
readInternet.setUrl(url)
readInternet.setMessagePort(m.port)
if readInternet.asyncPostFromString("your_post_data_string") then
    msg = m.port.waitMessage(0)
    if type(msg) = "roUrlEvent" then
        print msg
    end if
end if

This should make the correct POST request to your server's endpoint. Note that you need to pass the POST data as a parameter in asyncPostFromString()



来源:https://stackoverflow.com/questions/56597380/difference-between-asyncgettostring-and-asyncpostfromstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!