2016-04-08 21 views
0

我设置了API和Kong。我已经成功安装了Kong。事实上,我可以通过在cli上卷曲来访问我的API。然而,当我使用邮递员,我一直使用,我得到的回应Kong访问时回复404 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} 

如何过,当我尝试使用邮差,我得到一个404个状态响应。 与这个身体

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

我错过了什么吗?

免责声明: 我使用邮差,因为我很懒,因为我的客户也将主要使用邮递员。所以不要告诉我要使用curl来代替:)

回答

2

正好遇到了同样的问题。 为了发送给Kong,您需要添加Host标头,但Postman有一些受限制的标头被阻止,并且Host是其中一个。 您需要下载Chrome Inspector以发送主机标题。 欲了解更多详情 - https://www.getpostman.com/docs/requests

+0

谢谢!!!,这是一个很晚但仍然是寻找的答案:)谢谢你的链接..不知道他们有头限制... – rrw

1

您需要设置标题参数“主机”以便Kong找到您的API。

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

-H "Host: 192.168.33.10" 
+0

是的,我补充说,以及请求,仍然是一样的。 – rrw

+0

您可以检查邮差中的“生成代码”选项,并将其与curl命令匹配。这样你就会发现你是否正确设置了一切。 –

+0

这就是我遇到类似错误时的疑难解答。 –