尝试使用 python 请求访问此 soap 网络服务:http://bsestarmfdemo.bseindia.com/MFUploadService/MFUploadService.svc?WSDL
这是我的要求:
import requests
url="http://bsestarmfdemo.bseindia.com/MFUploadService/MFUploadService.svc?WSDL"
#headers = {'content-type': 'application/soap+xml'}
headers = {'content-type': 'application/soap+xml'}
body = """<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
<soap:Header/>
<soap:Body>
<tem:getPassword>
<!--Optional:-->
<tem:UserId>1003201</tem:UserId>
<!--Optional:-->
<tem:MemberId>10032</tem:MemberId>
<!--Optional:-->
<tem:Password>xxxxxxxx</tem:Password>
<!--Optional:-->
<tem:PassKey>xxxxxx123</tem:PassKey>
</tem:getPassword>
</soap:Body>
</soap:Envelope>"""
response = requests.post(url,data=body,headers=headers)
print (response.content)
这是响应:
b'
Sendera:ActionNotSupported
The message with Action \'\' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).'
如果我没理解错的话,我可能需要在请求中设置操作,但不知道该怎么做。我对 python 中的 SOAP 完全陌生,请建议如何解决这个问题。 谢谢!
最佳答案
只需将 SOAPAction 添加到标题中,例如:
headers = {'Content-type': 'text/xml;charset=UTF-8',
'SOAPAction': 'http://google.com/ISearchService/Find'
}
关于Python + SOAP : The message with Action \'\' cannot be processed at the receiver, 由于 EndpointDispatcher 的 ContractFilter 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37833718/