从 C# Vxml 浏览器访问 Cookie
C# 中的 Microsoft.Rtc.Collaboration.AudioVideo.VoiceXml.Browser 对象有一个 RunAsync 方法,该方法采用 Vxml 页面的 URI 来运行,还有一个 CookieCollection,理论上,它应该允许您传递可在脚本。我已经尝试了所有我能想到的从 Vxml 获取 cookie 的方法,但似乎没有任何附加到文档中。关于如何从 Vxml 访问传入的 cookie 有什么想法吗?
简单地说,这就是我所拥有的 vxml:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml" xml:lang="en-US" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml21/vxml.xsd" >
<form id="QueueForm">
<script>
<![CDATA[
function GetCookie(name)
{
var cookies = document.cookie;
return cookies;
}
]]>
</script>
<var name="cookie" expr="GetCookie('')" />
<field name="QueueField">
<prompt>
<value expr="cookie" />
were cookies
</prompt>
<grammar mode="dtmf" root="Dtmf">
<rule id="Dtmf">
<one-of>
<item> 1 </item>
</one-of>
</rule>
</grammar>
<filled>
<exit namelist="cookie"/>
</filled>
</field>
</form>
</vxml>
在调用代码中
_browser.SetAudioVideoCall(_call);
System.Net.CookieContainer cookies = new System.Net.CookieContainer(1);
cookies.Add(new System.Net.Cookie("data", "grapefruit", "/", "localhost"));
_browser.Run(_startPage, cookies);
......这会导致口头“Were cookies”。在我尝试过的所有情况下。
我尝试过在 cookie 对象上设置不同的域和路径,调用不同的 Javascript 对象以不同的方式获取 cookie,以及我能想到的任何其他方法,但无法访问 cookie。 Microsoft Vxml 示例项目也不包含访问 cookie 的示例。我确信有一种方法可以访问传入的项目,但我一直无法弄清楚如何;有什么想法吗?
The Microsoft.Rtc.Collaboration.AudioVideo.VoiceXml.Browser object in C# has a RunAsync method that takes a URI of a Vxml page to run and a CookieCollection that should, in theory, allow you to pass in parameters that can be used within the script. I've tried every conceivable method I can think of of getting cookies from the Vxml, and there do not seem to be any attached to the document. Any ideas on how to access the passed-in cookies from the Vxml?
At its simplist, this is what I had as the vxml:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml" xml:lang="en-US" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/vxml http://www.w3.org/TR/voicexml21/vxml.xsd" >
<form id="QueueForm">
<script>
<![CDATA[
function GetCookie(name)
{
var cookies = document.cookie;
return cookies;
}
]]>
</script>
<var name="cookie" expr="GetCookie('')" />
<field name="QueueField">
<prompt>
<value expr="cookie" />
were cookies
</prompt>
<grammar mode="dtmf" root="Dtmf">
<rule id="Dtmf">
<one-of>
<item> 1 </item>
</one-of>
</rule>
</grammar>
<filled>
<exit namelist="cookie"/>
</filled>
</field>
</form>
</vxml>
And this in the calling code
_browser.SetAudioVideoCall(_call);
System.Net.CookieContainer cookies = new System.Net.CookieContainer(1);
cookies.Add(new System.Net.Cookie("data", "grapefruit", "/", "localhost"));
_browser.Run(_startPage, cookies);
...which results in a spoken "Were cookies." in all instances I tried.
I've tried setting different domains and paths on the cookie object, calling different Javascript objects to get the cookie different ways and anything else I could think of, but haven't been able to access the cookie. The Microsoft sample projects for Vxml also do not contain an example of accessing cookies. I'm sure there's a way to access the items that are passed in, but I haven't been able to figure out how; any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是随 UCMA 3.0 一起提供的 VoiceXML 浏览器 API 的 PM。我联系了一位致力于实现该功能的开发人员,并请她调查这个问题。这是她的回应。
VXML 浏览器允许您通过 Run() 和 RunAsync() 方法将 CookieContainer 发送到浏览器中。在运行过程中,浏览器将向服务器发出 http 请求以获取 vxml 内容。此 cookie 容器作为 http 请求的一部分发送,服务器发送的任何 cookie 也最终在此容器中。这是根据设计。
这使您能够编写动态服务器,这些服务器可能会根据发送的 cookie 提供不同的 vxml。您还可以在会话完成后查看服务器 cookie 值。例如,黄金客户帐户可能是一个特殊的对话框,服务器可能会向您发送 cookie,帮助您确定浏览器完成后将呼叫发送到哪个队列。
但是,cookie 不会传递到 vxml 应用程序本身 - 也就是说,它们无法在 vxml 文档内部的 javascript 级别访问。我同意这会很方便,当然,习惯使用可以访问“document.cookie”的 html 浏览器的工程师可能会期望这一点。但 w3c vxml 规范并未规定该领域的标准行为,并且 Microsoft 浏览器也不提供此功能。
如果需要这样的功能,一种工程解决方案是让服务器读取 cookie 并动态生成 vxml,并将 cookie 值设置为某些 javascript 变量。
I was the PM for the VoiceXML browser API that we shipped with UCMA 3.0. I pinged one of the developers who worked on implementing it and asked her to look into this issue. Here is her response.
The VXML Browser allows you to send a CookieContainer into the browser in the Run() and RunAsync() methods. During the course of its run, the browser will be issuing http requests to servers for vxml content. This cookie container is sent as part of the http request and any cookies sent by the server also end up in this container. This is per design.
This enables you to write dynamic servers that might serve up different vxml based on cookies sent in. You can also see the server cookie values after the session has been completed. For instance, a gold customer account might be a special dialog and the server might send you cookies helping you figure out which queue to send the call to after the browser has completed.
However, the cookies are not passed into the vxml application itself – that is, they are not accessible at the javascript level inside of the vxml document. I agree that this would be convenient, and certainly, engineers used to dealing with html browsers where they can access “document.cookie” might expect this. But the w3c vxml specification doesn’t call out standard behavior in this area and the Microsoft browser doesn’t provide this functionality.
If such functionality were desired, one engineering solution would be to have your server read the cookies and dynamically generate vxml with the cookie values set to some javascript variables.