首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python - SOAP服务器无法识别HTTP标头的值

Python - SOAP服务器无法识别HTTP标头的值
EN

Stack Overflow用户
提问于 2017-01-07 07:27:36
回答 1查看 124关注 0票数 0

第一次使用SOAP时,我发现了多个类似错误消息的实例,但似乎都不适用于我。

代码是用Python (3.5)编写的。

以下是我试图向其发出请求的站点的确切示例:

代码语言:javascript
复制
POST /WS/OpenAPI.asmx HTTP/1.1
Host: bms.kaseya.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://bms.kaseya.com/Authenticate"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Authenticate xmlns="https://bms.kaseya.com/">
      <companyName>string</companyName>
      <userName>string</userName>
      <password>string</password>
    </Authenticate>
  </soap:Body>
</soap:Envelope>

我正在使用Python中的请求,看起来一切都很顺利:

代码语言:javascript
复制
import requests

companyName = 'My Company'
userName = 'My Username'
password = 'My Password'

url = 'https://bms.kaseya.com/WS/OpenAPI.asmx'

body = '''
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Authenticate xmlns="https://bms.kaseya.com/">
      <companyName>{}</companyName>
      <userName>{}</userName>
      <password>{}</password>
    </Authenticate>
  </soap:Body>
</soap:Envelope>'''.format(companyName,userName,password)

headers = {'Host':'bms.kaseya.com',
           'Content-Type':'text/xml; charset=utf-8',
           'Content-Length':str(len(body)),
           'SOAPAction':'"https://bms.kaseya.com/Authenticate"'}

r = requests.post(url, data=body, headers=headers)
print(r.text)

除了我得到的那部分:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Server did not recognize the value of HTTP Header SOAPAction: https://bms.kaseya.com/Authenticate.</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>

根据我所发现的,似乎SOAPAction的url是错误的?我真的是以他们为例,只是插入我的实时信息,我不知道我错在哪里,即使是我自己也不知道。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-07 11:09:18

别管它已经修好了。我的代码很好,正如预期的那样,这是由于他们的部分文档不好。稍微修复一些URL,一切都会按预期运行!

事实证明我们使用的是SOAP1.2,正确的示例应该是:

代码语言:javascript
复制
POST /WS/OpenAPI.asmx HTTP/1.1
Host: bms.kaseya.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:xsd="http://www.w3.org/2001/XMLSchema"     xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Authenticate xmlns="https://vorexlogin.com/">
      <companyName>string</companyName>
      <userName>string</userName>
      <password>string</password>
    </Authenticate>
  </soap12:Body>
</soap12:Envelope>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41516015

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档