对 HttpService 的 useProxy (Flex 3) 感到困惑
我有一个 Flex 应用程序,用户可以在其中提供资源的链接。 我想执行一个简单的验证并检查 url 是否实际上有效(不仅仅是结构,而是实际测试链接以确保我得到 200 OK)。
我想我只会使用 HttpService 并使用 HEAD 方法,但似乎只有当你将 useProxy 设置为 true 时才可用,但我尝试了,但仍然收到错误; 所以我很确定我做错了什么......这是代码片段
var service:HTTPService = new HTTPService();
service.method = "HEAD";
service.url = url;
service.useProxy = true;
service.addEventListener(ResultEvent.RESULT, result);
service.addEventListener(FaultEvent.FAULT, error);
service.send();
知道我做错了什么吗? 我也愿意接受有关如何检查 url 是否有效的其他建议(我更愿意直接从 Flex 执行此操作,而不必往返于服务器)。 谢谢。
编辑 (8/13/2009)
我通过使用 UrlLoader 并在其上分配 2 个侦听器实现了一个简单的 UrlValidator。 一个用于 IOError,另一个用于 Progress。 我的想法是,Progress 的行为类似于 HEAD 调用,我可以在收到一定量的数据后终止该流。 不幸的是,在 404 或 403 的情况下调用了进度事件,这违背了目的。 我也在 Open 事件中尝试过此操作,但得到了相同的结果。 有任何想法吗?
I have a flex app, where the user can provide a link to a resource. I want to perform a simple validation and check if the url is actually valid (not just structure, but actually test the link to ensure I get a 200 OK).
I figured I would just use HttpService and use the HEAD method, but it seems that this is only available when you set useProxy to true, but I tried that and I still get errors; so I am pretty sure I am doing something wrong....here is a snippet of the code
var service:HTTPService = new HTTPService();
service.method = "HEAD";
service.url = url;
service.useProxy = true;
service.addEventListener(ResultEvent.RESULT, result);
service.addEventListener(FaultEvent.FAULT, error);
service.send();
Any idea what I am doing wrong? I am also open to other suggestions as to how to check if a url is valid (I would prefer to do this directly from Flex, without having to go back & forth to the server). Thanks.
EDIT (8/13/2009)
I implemented a simple UrlValidator by using a UrlLoader and assigning 2 listeners on it. one for IOError, and the other for Progress. My thinking was that Progress would act similar to a HEAD call, and I could just kill the stream after some amount of data was received. Unfortunately, the progress event is called in the case of a 404 or 403, which defeats the purpose. I also tried this with the Open event, but got the same results. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Adobe 的 Flex 文档指出:
“当您不通过基于服务器的代理服务时,您只能使用 HTTP GET 或 POST 方法。但是,当您将 useProxy 属性设置为 true 并且您使用基于服务器的代理服务时,您还可以使用 HTTP HEAD、OPTIONS、TRACE 和 DELETE 方法。”
基于服务器的代理服务指的是 Live Cycle Data Services
我知道 AIR 支持使用 ServiceMonitor 的 HEAD 请求,但看起来 Flex 本身并不支持。
快速搜索一下,看起来有些人已经使用套接字来滚动他们自己的自定义 URLLoader 类,这些类可以访问请求标头 - 您可以尝试其中之一
Adobe's Flex docs state:
"When you do not go through the server-based proxy service, you can use only HTTP GET or POST methods. However, when you set the useProxy property to true and you use the server-based proxy service, you can also use the HTTP HEAD, OPTIONS, TRACE, and DELETE methods."
The server-based proxy service is referring to Live Cycle Data Services
I know AIR supports HEAD requests using the ServiceMonitor, but it looks like Flex on it's own doesn't.
Having a quick search around, it looks a few people have used sockets to roll their own custom URLLoader classes which can access the request headers - you could try one of them
每次我尝试在各种服务器上运行您的代码时,我都会收到策略错误,因此使用 Security.loadPolicyFile(url); 可能是一个好主意。 在尝试运行此代码之前首先? 我被赶出了办公室,但回家后我会尝试再次查看这个:)
Every time I try to run your code with various servers, I'm getting policy errors, so it might be a good idea to use Security.loadPolicyFile(url); first before trying to run this code? I'm getting thrown out of the office, but I'll try to look at this again when I get home:)
仅当
service.useProxy
设置为true
时才支持HEAD
。 但service.useProxy
指的是 BlazeDS/LCDS 中的HTTPProxyService
。 如果您仅创建客户端应用程序,则需要将service.useProxy
设置为false
并使用GET
或POST< /代码>。
另一个问题是,如果您绕过
HTTPProxyService
,则至少必须满足以下条件之一:crossdomain.xml
(跨域策略)文件。HEAD
is only supported ifservice.useProxy
is set totrue
. Butservice.useProxy
refers to theHTTPProxyService
in BlazeDS/LCDS. If you are creating a client application only, you will need to setservice.useProxy
tofalse
and use eitherGET
orPOST
.Another problem, is that if you are bypassing the
HTTPProxyService
, at least one of the following must be true:crossdomain.xml
(cross-domain policy) file must be installed on the web server hosting the document that allows access from the domain of the application.service.method = “HEAD”;
应该是“POST”或“GET”(默认为“GET”),但不是“HEAD”,
不必要,请删除该行...
如果 URL 可访问,您将收到 RESULT 事件。
service.method = "HEAD";
should be "POST" or "GET" (default is "GET") but not "HEAD"
not necessary, remove the line...
if the URL is reachable you will get a RESULT event.