访问 vi Postman 时 Kong 响应 404

Kong responds 404 when accessed vi Postman

我已经架设了一个API和Kong。我已经成功安装了Kong。事实上,我可以通过 cli 上的 curl 访问我的 APIs。但是,当我使用我一直使用的 Postman 时,我得到了响应

{
  "request_path": "/api/v1/",
  "message": "API not found with these values",
  "request_host": [
    "192.168.33.13"
  ]
}

Ps。我刚接触香港,所以请多多包涵。


$ kong start
[INFO] Kong 0.7.0
[INFO] Using configuration: /etc/kong/kong.yml
[INFO] Setting working directory to /usr/local/kong
[INFO] database...........cassandra keyspace=kong ssl=verify=false enabled=false replication_factor=1 contact_points=127.0.0.1:9042 replication_strategy=SimpleStrategy timeout=5000 data_centers=
[INFO] dnsmasq............address=127.0.0.1:8053 dnsmasq=true port=8053
[INFO] serf ..............-profile=wan -rpc-addr=127.0.0.1:7373 -event-handler=member-join,member-leave,member-failed,member-update,member-reap,user:kong=/usr/local/kong/serf_event.sh -bind=0.0.0.0:7946 -node=precise64_0.0.0.0:7946 -log-level=err
[INFO] Trying to auto-join Kong nodes, please wait..
[WARN] Cannot auto-join the cluster because no nodes were found
[WARN] ulimit is currently set to "1024". For better performance set it to at least "4096" using "ulimit -n"
[INFO] nginx .............admin_api_listen=0.0.0.0:8001 proxy_listen=0.0.0.0:8000 proxy_listen_ssl=0.0.0.0:8443
[OK] Started

$ curl -i -X POST --url http://localhost:8001/apis/ --data 'name=geospatial' --data 'upstream_url=http://192.168.33.10/' --data 'request_host=192.168.33.10'
HTTP/1.1 201 Created
Date: Fri, 08 Apr 2016 14:38:22 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/0.7.0

{"upstream_url":"http:\/\/192.168.33.10\/","id":"240e6cc6-626f-4629-9551-0d341a57adba","name":"geospatial","created_at":1460126302000,"request_host":"192.168.33.10"}

当我卷曲 api...

$ curl -i -X GET -H "Host: 192.168.33.10" "http://192.168.33.13:8000/api/v1/"
HTTP/1.1 200 OK
Date: Fri, 08 Apr 2016 14:56:04 GMT
Content-Type: application/json
Content-Length: 70
Connection: keep-alive
Server: Werkzeug/0.11.4 Python/2.7.6
X-Kong-Upstream-Latency: 4
X-Kong-Proxy-Latency: 0
Via: kong/0.7.0

{"status": 200, "message": 200, "data": "Hello World!", "error": null}

当我尝试使用 Postman 时,我收到了 404 状态响应。 有了这个 body

{
  "request_path": "/api/v1/",
  "message": "API not found with these values",
  "request_host": [
    "192.168.33.13"
  ]
}

我是不是漏掉了什么?

免责声明: 我使用 Postman 是因为我很懒惰,而且我的客户也大多会使用 Postman。所以不要告诉我改用 curl :)

您需要设置名为 "Host" 的 header 参数,以便 Kong 找到您的 API.

可以看到你的curl命令有这个参数

-H "Host: 192.168.33.10"

刚遇到同样的问题。 为了发送到 Kong,您需要添加 Host header,但是 Postman 有一些受限制的 header 被阻止,Host 就是其中之一。 您需要下载 Chrome Inspector 发送主机 header。 更多细节 - https://www.getpostman.com/docs/requests