2016-04-08 19 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

這就是我遇到類似錯誤時的疑難解答。 –