如何Dify的SOAP服务调用为?
摘要:前提: Dify中使用Http请求节点,执行SOAP接口,报错400 先在本地执行curl进行测试接口服务是否正常 curl -X POST -H "Content-Type: textxml; charset=
前提:
Dify中使用Http请求节点,执行SOAP接口,报错400
先在本地执行curl进行测试接口服务是否正常
curl -X POST -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction: \"http://****/********\"" -d "需要传参的xml" https://****/********/***.asmx
发现服务正常,接口正常返回
直接换代码执行节点实现:
import requests
import urllib3
# Disable SSL warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def send_soap_request():
url = "https://****/********/***.asmx"
headers = {
"Content-Type": "text/xml; charset=utf-8",
"SOAPAction": '"http://****/********"'
}
soap_body = "需要传参的xml"
try:
response = requests.post(url, data=soap_body, headers=headers, timeout=30, verify=False)
pass
if response.status_code == 200:
return response.text
else:
return str(response.status_code)
except requests.exceptions.RequestException as e:
return f"RequestException: {str(e)}"
except Exception as e:
return f"Exception: {str(e)}"
def main():
result = send_soap_request()
return result
PS:
SSL认证需要访问方信任对应域名的根证书签发机构,可去掉相关抑制请求
