|
首先下載POSTMAN
安裝好以後先到AZURE Portal endpoints 找到遠端SERVER路徑
如:http://7688d3eb-fceb-47a8-b4df-921329fafd76.westus.azurecontainer.io/score
POSTMAN PYTHON SERVER JSON
開啟POSTMAN -> File -> New Postman Windows
POSTMAN PYTHON SERVER JSON
Create a request
POSTMAN PYTHON SERVER JSON
POST->輸入URL-> Body -> raw -> 貼上資料 -> Send
最後會解譯出來
POSTMAN PYTHON SERVER JSON
也可用jupyter notebook
寫一段程式
- url = 'http://df055355-8f07-4440-a6d6-37331b6a5b69.eastus.azurecontainer.io/score'
- import urllib.request
- import json
- x_new = [[2, 180, 74, 24, 21, 23.9091702, 1.488172308, 22]]
- data = str.encode(json.dumps({"data": x_new}))
- headers = {'Content-Type':'application/json'}
- req = urllib.request.Request(url, data, headers)
- response = urllib.request.urlopen(req)
- result = response.read()
- print(result)
複製代碼
或
- import requests
- import json
- endpoint = 'http://df055355-8f07-4440-a6d6-37331b6a5b69.eastus.azurecontainer.io/score'
- x_new = [[2,180,74,24,21,23.9091702,1.488172308,22],
- [0,148,58,11,179,39.19207553,0.160829008,45]]
- # Convert the array to a serializable list in a JSON document
- input_json = json.dumps({"data": x_new})
- # Set the content type
- headers = { 'Content-Type':'application/json' }
- predictions = requests.post(endpoint, input_json, headers = headers)
- predicted_classes = json.loads(predictions.json())
- predicted_classes
複製代碼
|
|