liseen / lua-resty-http

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

I have this code , its return NIL #33

Closed ryannining closed 9 years ago

ryannining commented 9 years ago
local http = require("resty.http")
local hc = http:new()
local ok, code, headers, status, body = hc:request({
  url = "http://www.tokoled.net/uploads/1920.jpg",
  method = "GET",
  headers = { },
  body = ""
})
return ngx.say(body)

Are my code correct ? i have new project to migrate my other website to LUA+ OpenResty, but it need phpcurl, so i think this package is suitable to replace phpcurl function.

wendal commented 9 years ago

ngx.say always return nil, what is the point??

ryannining commented 9 years ago

oh sorry, wrong code

ngx.say(body)

Body is nil ? is it correct way ? i am trying to load image from other website and process is in my app code.

ryannining commented 9 years ago

i try to ngx.say all result from the request function

ngx.say(ok,code,headers,status,body)

Result: nilsock connected failed no resolver defined to resolve "www.tokoled.net"nilnilnil

wendal commented 9 years ago

add above config into nginx.conf

resolver 8.8.8.8; 
ryannining commented 9 years ago

Thx, its work now...