为什么这个 Flex 的“Hello World”是这样的? 应用程序无法获取我的远程 HTTPService 调用的结果?
当我访问 http://localhost:3000/hello/sayhello 时,Rails 输出:
hello world!
作为 HTML。
但是,当我运行这个 Flex 远程“Hello World”应用程序时,我看到一个按钮和一个文本框,但它没有获取对我的 Rails url 的 HTTPService 调用的输出。 有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
backgroundGradientColors="[#ffffff, #c0c0c0]"
width="100%"
height="100%">
<mx:HTTPService
id="helloSvc"
url="http://localhost:3000/hello/sayhello"
method="POST" resultFormat="text"/>
<mx:Button label="call hello service"
click="helloSvc.send()"/>
<mx:TextInput text="{helloSvc.lastResult}"/>
</mx:Application>
When I go to http://localhost:3000/hello/sayhello, Rails outputs:
hello world!
as HTML.
But when I run this Flex remote "Hello World" app, I see a button and a textbox but it does not pick up the output of the HTTPService call to my Rails url. Any ideas why?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
backgroundGradientColors="[#ffffff, #c0c0c0]"
width="100%"
height="100%">
<mx:HTTPService
id="helloSvc"
url="http://localhost:3000/hello/sayhello"
method="POST" resultFormat="text"/>
<mx:Button label="call hello service"
click="helloSvc.send()"/>
<mx:TextInput text="{helloSvc.lastResult}"/>
</mx:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将您的代码复制并粘贴到新的 Flex 应用程序中,修改 URL 以指向我知道适用于 Flex 应用程序的脚本,并且效果很好。
我还更改了服务器端脚本以使用换行符打印“hello world”,效果也很好。
您的 Flex 代码对于纯文本似乎可以正常工作,但数据显示和数据本身之间显然没有连接。 我对 Rails 没有经验,但我想知道你的服务器是否正在输出无法解析的数据,并且任何异常都会被吞噬。
我的建议是:更改“sayhello”脚本,使其仅打印内容标题和“hello world”——全部以纯文本形式显示。 确保它在浏览器中输出,然后查看它是否也适用于 Flex 应用程序。 如果是这样,您的 Rails 应用程序可能正在输出需要解析的内容,而不是简单地设置为文本输入。 如果没有,您将需要进行更多调试。
顺便说一句,我尝试了纯文本输出和 XML 输出。 在这两次尝试中,我都能够查看文本输入字段中的内容。
I copied and pasted your code into a new Flex App, modifying the URL to point to a script I know works with Flex apps, and it worked just fine.
I also changed my server-side script to print 'hello world' with a newline, and that worked fine as well.
Your Flex code appears to be working OK with plain-text, but something is obviously not connecting between the data display and the data itself. I'm not experienced with Rails, but I wonder if your server is outputting data which cannot be parsed, and any exceptions are getting swallowed.
Here's my suggestion: change your 'sayhello' script so it simply prints a content-header and 'hello world' -- all in plain-text. Make sure it outputs in the browser, and then see if it also works in the Flex app. If it does, your Rails app is probably outputting content which needs to be parsed, as opposed to simply set to the text input. If it doesn't, you'll need to do more debugging.
BTW, I tried this with both plain-text output and XML output. In both attempts, I was able to view the content in the text-input field.
我并不肯定,因为我看不到您的服务将回复的 XML,但我认为这可能是以下两件事之一:
1) 您没有元素来格式化对您的服务的请求。 查看此模板...Flex 3 帮助
这可能会导致请求永远无法正确发出,或者您的服务因请求而阻塞并且永远不会返回结果。 您必须调试该服务才能查看它如何处理请求。
2) 您的服务正在返回带有命名空间的 XML 结果。 在这种情况下,您需要查看 另一个 Flex 3 帮助,介绍如何处理 e4x 格式的 XML 结果。
I'm not positive, as I can't see the XML that your service would reply with but I think it's probably one of two things:
1) Your has no element to format the request to your service. Check this out for a template...Flex 3 Help
That could either cause the request to never properly be made or your service to choke on the request and never return a result. You'd have to debug the service to see how it's handling the request.
2) Your service is returning an XML result with namespaces. In that case, you're going to need to check out Another Flex 3 Help about how to handle XML results in the e4x format.