访问vi Postman时,Kong回复404

时间:2016-04-08 15:09:56

标签: api curl postman kong

我已经建立了一个API和Kong。我已经成功安装了Kong。事实上,我可以通过cli上的curl访问我的API。但是,当我使用Postman时,我会一直使用它,我得到了回复

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

聚苯乙烯。我是新来的kong所以请耐心等待。

$ 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状态响应。 与这个身体

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

我错过了什么吗?

声明: 我正在使用Postman,因为我很懒,因为我的客户也会主要使用Postman。所以不要告诉我要使用curl:)

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:1)

您需要设置名为" Host" 的标头参数,以便找到您的API。

您可以看到curl命令具有此参数

-H "Host: 192.168.33.10"