我可以使用flask run命令列在本地機器上運行 Flask 應用程式/API 。這將設定一個本地服務器(對我來說,在http://127.0.0.1:5000/),并在該地址運行應用程式。
完成此操作后,我只需http://127.0.0.1:5000/<route>在瀏覽器中訪問即可向我的應用程式發出 GET 請求。如何向應用程式發出 POST 請求?我還有一些要包含在 POST 請求正文中的引數。
uj5u.com熱心網友回復:
您不能在瀏覽器中POST使用請求URL。它需要HTML具有
<form method="POST">
</form>
所以你的服務器會發送這個頁面給你。
相反,瀏覽器,你可以使用Python模塊,如urllib或簡單的requests可以運行.get(),.post(...)等等。
在示例中,我使用
您也可以嘗試使用curl 之類的控制臺程式
curl https://httpbin.org/post -X POST -d "search=hello world"
{
"args": {},
"data": "",
"files": {},
"form": {
"search": "hello world"
},
"headers": {
"Accept": "*/*",
"Content-Length": "18",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "curl/7.68.0",
"X-Amzn-Trace-Id": "Root=1-61687da3-5eaaa4ff6419c36639a2cc5d"
},
"json": null,
"origin": "83.11.118.179",
"url": "https://httpbin.org/post"
}
順便提一句:
一些API在檔案中以curl為例來展示如何使用API
有頁面https://curl.trillworks.com可以轉換curl為 Python requests(但有時無法正確執行)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316756.html
