curl - 如何使用 curl 获取数据而不是网站?
问题描述
我有这段代码,据说它从 url 获取了一个 redis 键值:
location /getkey/(^[a-zA-Z0-9_.-]*)$ {
add_header 'Access-Control-Allow-Origin' '*';
content_by_lua_block {
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000) -- 1 sec
-- or connect to a unix domain socket file listened
-- by a redis server:
-- local ok, err = red:connect("unix:/path/to/redis.sock")
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.say("failed to connect: ", err)
return
end
ngx.say("set result: ", ok)
ngx.say("Getting $1")
local res, err = red:get("$1")
if not res then
ngx.say("failed to get $1: ", err)
return
end
if res == ngx.null then
ngx.say("$1 not found.")
return
end
ngx.say(res)
}
}
目前我正在使用这个 curl 命令来获取数据响应:
curl -X GET http://localhost/getkey/insertkeyhere
但是我得到了一个html:
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>openresty/1.13.6.2</center>
</body>
</html>
在我的日志中,它显示找不到目录/位置:
2018/07/17 13:38:17 [error] 18425#18425: *179 open() "/usr/local/openresty/nginx/html/getkey/hello2" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /getkey/hello2 HTTP/1.1", host: "localhost"
解决方案
推荐阅读
- javascript - Jquery InputMask 动态验证
- mysql - 将一个表中的元素与另一个表中共享相同外键的元素之和进行比较
- python - Pandas:具有固定起点和终点的直方图
- android - Android闪屏背景而不是windowBackground
- vespa - 在 Vespa 中使用 tensorflow 神经模型重新排序
- vb.net - 位置 0 处没有行。IndexOutofRangeException
- vbscript - Windows 7 不会自动刷新文件夹,使用 Sendkey 制作了一个 vbs 脚本来刷新
- c++ - C ++中的增量和三元运算符优先级
- javascript - 更改鼠标悬停时的粒子效果
- css - 使一个 SPAN 适合另一个 SPAN 高度