Answer the question
In order to leave comments, you need to log in
How to parse an array in nginx - lua?
I get the response body from php via ngx.location.capture , where there is an array in the response: ['success' => true, 'key1' => 'value1'];
When I output ngx.say("body:", res.body), I get res.body:array|
How can I get the value of key1?
res.body.key1,res.body.["key1"],res.body[0] - don't help
nginx.conf:
location /IdentityAccess/loginService {
rewrite ^/IdentityAccess^/ /$1 break;
proxy_pass http://identityaccess/login;
proxy_redirect off;
}
location /IdentityAccess/login {
lua_need_request_body on;
content_by_lua '
local res = ngx.location.capture("/IdentityAccess/loginService",{ method = ngx.HTTP_POST,body=ngx.var.request_body })
if res then
nxg.var.resbody = res.body
ngx.say("status: ", res.status)
ngx.say("body:", res.body)
else
ngx.say("error")
end
';
}
Answer the question
In order to leave comments, you need to log in
Tried:
key = res.body.key1 and key = res.body.["key1"]
ngx.say("body:", key)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question