我是MIT App Inventor的新手,能够通过UI功能工作,但不太清楚如何从Web组件发出SOAP样式的发布请求。为MIT App Inventor构建SOAP风格的发布请求XML?
我能够用Python 2.7版做到这一点,这里是代码:
#!/usr/bin/env python
# encoding: utf-8
import requests
## Remeber: Way too many people accessing this server error may occur if any other instance is opened
request = u"""<?xml version='1.0' encoding='utf-8'?>
<SOAP-ENV:Envelope xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://localhost/HTSI_Pages/HTSI_DataService" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<writeString xmlns="http://localhost/HTSI_Pages/HTSI_DataService">
<tagStr>MASTER.STATEMASTER</tagStr>
<entryStr>ReadyAllManagers</entryStr>
<typeStr>String</typeStr></writeString></SOAP-ENV:Body>
</SOAP-ENV:Envelope>"""
encoded_request = request.encode('utf-8')
headers = {"Host": "10.216.224.30",
"Content-Type": "text/xml; charset=UTF-8",
"Content-Length": len(encoded_request)}
response = requests.post(url="http://10.216.224.30/HTSI_Pages/HTSI_DataService.asmx",
headers = headers,
data = encoded_request,
verify=False)
print unicode(response.text)
有了一点谷歌搜索我能找到@Taifun's梦幻般的回答,显示如果我要使它可能是我最好的工作打赌是在web.request标题下以列表的形式构建XML。
所以,我在这一点上不知道在何处以及如何我可以编码为UTF-8格式的请求,并设定主机/字符集等。(正如我所说的,小白@应用发明)
PS:因为它是一台响应这个请求的实际机器,所以我限制自己尝试所有可能的选项组合以最终找出答案,尽管这是我通常的首要考虑(机器中的服务器位于嵌入式PLC ,不是由我写的,所以我不知道它将如何对不同的组合作出反应。)
因此,任何帮助设计App Inventor中的此请求将不胜感激。
更新:我按照步骤到达了这个街区。 点击按钮我现在收到错误Error 1103: unable to post or put text
。随后是uriencoded xml。
屏幕不够大,看不到完整的错误,但一些使用Google提示这可能是由于防火墙/网络。你有什么建议?
更新2:所以我设置屏幕滚动,删除\ N,字符集和分号,把开放的XML编码的长度,并运行它反对PostText
以及PostTextWithEncoding
。
他们都没有提出事件GotText
,我想因为标签文本没有被设置,但我得到了某种弹出消息的错误。附图。
我已经将相关块@Taifun的原始问题添加了更新。感谢您关注此事。 – S4nd33p
好吧,在这些工作,并会回复一下。另一件事......在构建XML时,是否应该使用\ n来格式化为换行符,还是应该将其从我用作存储库的文本文件复制粘贴后的方式保留。注意:在文本文件中,我使用通常的新行格式化方式创建了xml内容。 – S4nd33p
尝试了这些步骤,并更新了问题,但它仍然不存在,顺便说一句,我不能感谢你在这个@Taifan上与我密切关注。 – S4nd33p