AsyncGetToString和AsyncPostFromString之间的区别?

时间:2019-06-14 11:36:32

标签: roku brightscript

我创建了一个Web API。我叫明亮的脚本。我指的是https://developer.roku.com/en-gb/docs/references/brightscript/interfaces/ifurltransfer.md#head-as-dynamic/ 所有方法,但不了解,没有人知道AsyncGetToString和AsyncPostFromString方法的实际用法。

我在Roku中使用以下代码

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

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

但是它每次都会触发My Roku Server中的Get方法。

此处为Roku服务器代码(使用Get方法)

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

它总是以两种方式调用此方法 (使用Post方法)

 [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
 }

请任何人帮助我。

1 个答案:

答案 0 :(得分:0)

AsyncPostFromString()允许您发出异步POST请求,该请求一旦完成,就会向与其关联的消息端口发送一条消息(在本例中为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

这应该向服务器的端点发出正确的POST请求。请注意,您需要将POST数据作为参数传递给asyncPostFromString()