简体   繁体   English

lua 中的 Get.network.request 响应头

[英]Get network.request response headers in lua

I'm using.network.request like this:我像这样使用.network.request:

network.request( fullUrl, "POST", networkListener, params)

and receiving the response in my.network listener as such:并在 my.network 侦听器中接收响应:

local function networkListener( event )
    if ( event.isError ) then
        response = {};
    else
        response = json.decode(event.response);
    end
end

I am receiving the body response of the request but I want to receive the request's response headers as well.我正在接收请求的正文响应,但我也想接收请求的响应标头。 How can I achieve this?我怎样才能做到这一点?

Thanks a lot!非常感谢!

The documentation for network.request says:network.request的文档说:

 network.request( url, method, listener [, params] )

listener (required)听众(必填)

Listener .听众 The listener function invoked at various phases of the HTTP operation.侦听器 function 在 HTTP 操作的各个阶段调用。 This is passed anetworkRequest event.这是通过networkRequest事件。

Andthe documentation for networkRequest links to event.responseHeaders , which gives this example: networkRequest的文档链接到event.responseHeaders ,它给出了这个例子:

-- Print the Content-Type header value for a response
local function networkListener( event )
    print( "Content-Type of response is: " .. event.responseHeaders["Content-Type"] )
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM