2016-11-17 36 views
0
import Flask 
app.route('/urlinfo/1/<URL>', methods=['GET']) 
def search(URL): 
    print URL 

我正在curl命令來測試它如何瓶配置考慮URL作爲一個參數通過curl命令傳遞

curl http://127.0.0.1:5000/urlinfo/1/http://www.dsdsd.com 

由於網址包括「//」瓶把它作爲第二個參數並拋出一個錯誤。

1.How傳遞整個URL作爲一個參數在

curl http://127.0.0.1:5000/urlinfo/1/http://www.dsdsd.com/path command? 

2.How檢查輸入網址是有效的?

回答

3

你的裝飾改成這樣:

@app.route('/urlinfo/1/<path:URL>', methods=['GET']) 

通過添加path到URL參數,斜線應該被接受。

+0

謝謝是的它解決了問題。我可以驗證URL是有效的。我的意思是基本檢查? – guri

+0

@guri看看這個答案http://stackoverflow.com/a/32171869/7090605 –

+0

感謝分享鏈接。我偶然發現它,但我試圖避免安裝額外的軟件包,並嘗試與內置庫實現 – guri