我(尝试)使用“请求”库通过Python发送以下内容:
import requests
def Post_Value(date,time,dmg,pbxName,pbxDN,peakcalls,maxcalls,utilz,totalcalls):
payload = '"<<<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">\
<?xml version="1.0" encoding="utf-8" ?> \
<s:Body> \
<InsertSIPRecord xmlns="http://tempuri.org/"> \
<applicationID>%s</applicationID> \
<Date>%s</Date> \
<TimeofPeakUsage>%s</TimeofPeakUsage> \
<DMG>%s</DMG> \
<PBXDN>%s</PBXDN> \
<PBXName>%s</PBXName> \
<PeakCalls>%s</PeakCalls> \
<MaxConcurrentCalls>%s</MaxConcurrentCalls> \
<PercentUtilization>%s</PercentUtilization> \
<TotalCalls>%s</TotalCalls> \
</InsertSIPRecord> \
</s:Body> \
</s:Envelope>>>'%(AppID,date,time,dmg,pbxDN,pbxName,peakcalls,maxcalls,utilz,totalcalls)
try:
r = requests.post(('http://%s'%host), data=payload)
except Exception,e:
msg += " %s \n %s \n"%(Exception,e)
print msg
sys.exit()
response= r.text
return response
我收到415错误:
HTTP/1.1 415 Cannot process the message because the content type 'application/octet-stream' was not the expected type 'text/xml; charset=utf-8'.\r\n
如何更改内容类型以符合预期?