我正在使用CitectSCADA的CitectVBA环境通过Msxml2.XMLHTTP
对象向Twilio的Twimlets服务器发出POST请求。在发现这个与Office的VBA v6之间的一些差异之后,我确实设法得到了发出POST请求的东西。
Dim TwiMLURL As String
TwiMLURL = "http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%3CSay%3EThis%20Is%20a%20test.%20Say%20Alarm%20Trip%20" _
& almNum &".%3C%2FSay%3E%0A%3C%2FResponse%3E&"
Dim http As Object
Set http = CreateObject("Msxml2.XMLHTTP")
http.Open "POST", GetCallURL(), False, ACCOUNTSID, AUTHTOKEN
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Dim postData As Variant
postData = "From=" & TwilioNumber _
& "&To=" & toNumber _
& "&Url=" & TwiMLURL
' send the POST data
Print postData
http.send postData
我现在遇到的问题是,我为请求的Url
参数提供的输入具有XML字符的有效URL编码,但我得到的响应表明这些代码通过了相应的HTML&符号字符代码。
上面代码的输出:
The thread 1 has started.
From=+15555556430&To=+15555551597&Url=http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%3CSay%3EThis%20Is%20a%20test.%20Say%20Alarm%20Trip%20111.%3C%2FSay%3E%0A%3C%2FResponse%3E&
<?xml version='1.0' encoding='UTF-8'?><TwilioResponse><RestException><Code>21205</Code><Message>Url is not a valid url: http://twimlets.com/echo?Twiml=<Response><Say>This Is a test. Say Alarm Trip 111.</Say></Response></Message><MoreInfo>https://www.twilio.com/docs/errors/21205</MoreInfo><Status>400</Status></RestException></TwilioResponse>
The thread 1 has terminated.
关于翻译发生地点的任何想法?我非常接近能够让Citect打电话给操作员的电话并阅读当前活动警报的代码!
更新:我刚刚通过Hurl.it运行了我的POST请求,并确认Twilio正确接收了该请求 - 呼叫通过我的手机并按要求读取Twimlet编码的消息。所以问题在于Msxml2.XMLHTTP
。关于我如何解决这个问题的任何想法?
更新2: Encoding “<” and “>” while sending XML via HTTP Post解决了初始POST错误:我已更新了我的请求标题。
http.setRequestHeader "Content-Type", "text/xml; charset=""utf-8"""
然而,现在,我得到一个回复,说没有指定“收件人”号码:
<?xml version='1.0' encoding='UTF-8'?><TwilioResponse><RestException><Code>21201</Code><Message>No 'To' number is specified</Message><MoreInfo>https://www.twilio.com/docs/errors/21201</MoreInfo><Status>400</Status></RestException></TwilioResponse>
我的电话号码格式为%2B15555556430
。这里有另一个编码问题吗?我甚至不知道如何调查Msxml2.XMLHTTP这次发送的内容。
更新3:问题出在MSXML2.XMLHTTP上。当我将帖子数据发送到httpbin.org/post以使其回显我发送的内容时,它会返回以下对象,具体取决于我选择的Content-Type
标题:
使用text/xml; charset=""utf-8""
:
"args": {},
"data": "From=%2B15555556430&To=%2B15555551597&Url=http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%20%20%3CSay%3EM%20G%20141%20E%20Q%20P%20S%20A%20Alarm%20Trip%20111%3C%2FSay%3E%0A%3C%2FResponse%3E&",
"files": {},
"form": {},
使用application/x-www-form-urlencoded
:
"args": {},
"data": "",
"files": {},
"form": {
"From": "+15555556430",
"To": "+15555551597",
"Url": "http://twimlets.com/echo?Twiml=<Response>\n <Say>M G 141 E Q P S A Alarm Trip 111</Say>\n</Response>"
},
使用application/json
:
"args": {},
"data": "From=%2B15555556430&To=%2B15555551597&Url=http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%20%20%3CSay%3EM%20G%20141%20E%20Q%20P%20S%20A%20Alarm%20Trip%20111%3C%2FSay%3E%0A%3C%2FResponse%3E&",
"files": {},
"form": {},
我实际上尝试在WinHttp.WinHttpRequest.5.1
中代替Msxml2.XMLHTTP
进行交换,并得到完全相同的结果。有什么想法吗?
答案 0 :(得分:0)
看起来您要发布到TwiMLURL
看似编码的内容。您将发布到GetCallURL()
的返回值。
http.Open "POST", GetCallURL(), False, ACCOUNTSID, AUTHTOKEN