简体   繁体   中英

Get network.request response headers in lua

I'm using.network.request like this:

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

and receiving the response in my.network listener as such:

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( url, method, listener [, params] )

listener (required)

Listener . The listener function invoked at various phases of the HTTP operation. This is passed anetworkRequest event.

Andthe documentation for networkRequest links to event.responseHeaders , which gives this example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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