liseen / lua-resty-http

Lua http client driver for the ngx_lua based on the cosocket API
188 stars 70 forks source link

Error - sock connected failed no resolver defined to resolve #36

Closed cpanato closed 9 years ago

cpanato commented 9 years ago

Hello

I'm very new and maybe this is the issue :)

Im trying to just make a test and then follow the example and change a little bit

location /test {
            content_by_lua '
                local http = require("resty.http")
                local hc = http:new()

                local ok, code, headers, status, body  = hc:request {
                    url = "http://www.google.com",
                    method = "GET",
                    headers = { ["Content-Type"] = "application/json" },
                    body = "",
                }

                ngx.say(ok)
                ngx.say(code)
                ngx.say(body)
            ';
        }

but Im getting this error:


nil
sock connected failed no resolver defined to resolve "www.google.com"
nil

What is wrong or what Im missing?

thanks

wendal commented 9 years ago

add this to you server {...}

resolver 8.8.8.8;
qrof commented 9 years ago

You should add DNS resolver to nginx conf.

IF you are targeting same URL it's also better to create a reverse proxy in nginx conf and use ngx.location.capture

On čet., nov. 19, 2015 at 9:55 pop., Carlos Tadeu Panato Junior < notifications@github.com [notifications@github.com] > wrote: Hello

I'm very new and maybe this is the issue :)

Im trying to just make a test and then follow the example and change a little bit

location /test { content_by_lua ' local http = require("resty.http") local hc = http:new()

            local ok, code, headers, status, body  = hc:request {
                url = "http://www.google.com",
                method = "GET",
                headers = { ["Content-Type"] = "application/json" },
                body = "",
            }

            ngx.say(ok)
            ngx.say(code)
            ngx.say(body)
        ';
    }

but Im getting this error:

nil sock connected failed no resolver defined to resolve "www.google.com" nil

What is wrong or what Im missing?

thanks

— Reply to this email directly or view it on GitHub [https://github.com/liseen/lua-resty-http/issues/36] .[https://github.com/notifications/beacon/ABI2MjvxlbPO7kye_WZQt7yV_Z9lvBfCks5pHi7dgaJpZM4Gl48M.gif]

cpanato commented 9 years ago

Thanks!!!