import http.client
conn = http.client.HTTPConnection("localhost:8181")
device_id = 1
while device_id < 1000:
payload = "\n{\n \"deviceId\": \"device_id\",\n \"osVendor\": \"abcd\"\n}"
headers = {
'content-type': "application/json",
'cache-control': "no-cache",
'postman-token': "03ac94dc-d208-95dd-7bf2-2e6c1f194316"
}
conn.request("POST", "/PNBQC/v1/registerbox", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
答案 0 :(得分:0)
您可以将有效负载创建为字典,然后在操作后将其转储到字符串中。
import json
device_id = 1
while device_id < 1000:
payload = {"deviceId": device_id, "osVendor": "abcd"}
payload = json.dumps(payload)
device_id += 1