如果我从POSTMAN发送一个REST请求,并跟随正文:
{"mode":"sync","messageType":"2fc4af5d7543ff1f22a9","messages":[{"timestamp":12345,"Brightness":12345,"Temperature":23456,"Humidity":345678}]}
工作正常。 但是如果我尝试从python发送它:
import os
import glob
import time
import requests
import json
import string
import datetime
import time
url = 'http://...'
dev = 'c46e9512-9358-4046-ba88-7b78b0d282d0'
authStr = 'Bearer ....'
url = url + dev
headers = {"Content-type": 'application/json;charset=utf-8', "Authorization": authStr}
dt = int(time.time()) #dt= 1479901984
data = '{"mode":"sync","messageType":"2fc4af5d7543ff1f22a9","messages":[{"timestamp":1029283,"Brightness":999.0,"Temperature":16.3,"Humidity":80.9}]}'
r = requests.post(url, data=data, headers=headers)
print r.text
print "status code = ", r.status_code
它看起来很奇怪:
我收到状态200(没有正文)和服务器端的响应它不起作用。
还有更多:如果我更改了邮件正文,那它是不正确的(所以我应该收到一个错误)我仍然收到状态为200的响应。它接缝的身体被忽略:(
URL和标头在两个请求中都是相同的。
有什么问题?