使用 Flex 创建 REST 客户端是否可行? [英] Is it feasible to create a REST client with Flex?

查看:20
本文介绍了使用 Flex 创建 REST 客户端是否可行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开始一个使用在 Java 中实现的 Restful 架构的项目(使用新的 JAX-RS 标准)

I'm starting a project using a Restful architecture implemented in Java (using the new JAX-RS standard)

我们计划使用 Flex 应用程序开发 GUI.我已经发现使用 HTTPService 组件的这个实现存在一些问题(响应错误代码、标头访问......).

We are planning to develop the GUI with a Flex application. I have already found some problems with this implementation using the HTTPService component (the response error codes, headers access...).

你们中的任何人都有类似项目的经验.可行吗?

Any of you guys have some experience in a similar project. Is it feasible?

推荐答案

这里的问题是很多围绕这个问题的网络讨论已经有一年或更长时间了.我现在正在做同样的研究,这就是我今天学到的东西.

The problem here is that a lot of the web discussions around this issue are a year or more old. I'm working through this same research right now, and this is what I've learned today.

这篇 2008 年 8 月的 IBM Developer Works 文章作者:Jorge Rasillo 和 Mike Burr 展示了如何制作 Flex 前端/RESTful 后端应用程序(PHP 和 Groovy 中的示例).不错的文章.无论如何,这是要点:

This IBM Developer Works article from August 2008 by Jorge Rasillo and Mike Burr shows how to do a Flex front-end / RESTful back-end app (examples in PHP and Groovy). Nice article. Anyway, here's the take away:

  • 他们的 PHP/Groovy 代码使用并期望 PUT 和 DELETE.
  • 但 Flex 代码必须使用 POST,但将 HTTP 标头 X-Method-Override 设置为 DELETE(我认为您可以对 PUT 执行相同操作).
  • 请注意,这不是上面讨论的代理方法.
  • Their PHP/Groovy code uses and expects PUT and DELETE.
  • But the Flex code has to use POST, but sets the HTTP header X-Method-Override to DELETE (you can do the same for PUT I presume).
  • Note that this is not the Proxy method discussed above.


// Flex doesn't know how to generate an HTTP DELETE.
// Fortunately, sMash/Zero will interpret an HTTP POST with
// an X-Method-Override: DELETE header as a DELETE.
deleteTodoHS.headers['X-Method-Override'] = 'DELETE';

这里发生了什么?IBM Web 服务器拦截并将POST with DELETE"解释为 DELETE.

What's happening here? the IBM web server intercepts and interprets the "POST with DELETE" as a DELETE.

所以,我进一步挖掘并发现了这个与 Don Box(最初的 SOAP 专家之一)发表帖子并进行讨论.显然,这是一个相当标准的行为,因为某些浏览器等不支持 PUT 和 DELETE,并且是一种已经存在一段时间的变通方法.这是一个片段,但还有更多讨论.

So, I dug further and found this post and discussion with Don Box (one of the original SOAP guys). Apparently this is a fairly standard behavior since some browsers, etc. do not support PUT and DELETE, and is a work-around that has been around a while. Here's a snippet, but there's much more discussion.

如果我正在构建一个 GData 客户端,我真的想知道为什么我要费心使用 DELETE 和 PUT 方法,因为 X-HTTP-Method-Override 将在更多案例/部署中工作."

"If I were building a GData client, I honestly wonder why I'd bother using DELETE and PUT methods at all given that X-HTTP-Method-Override is going to work in more cases/deployments."

我的结论是,如果您的 Web 端支持此 X-Method-Override 标头,那么您可以使用此方法.Don Box 的评论让我觉得它得到了很好的支持,但我还没有确认.

My take away from this is that if your web side supports this X-Method-Override header, then you can use this approach. The Don Box comments make me think it's fairly well supported, but I've not confirmed that yet.

另一个问题是关于能够读取 HTTP 响应标头.同样,来自 2007 年 Nathan de 的一篇博客文章Vries,我们看到这个讨论.他用自己的评论跟进了那篇博文和讨论:

Another issue arises around being able to read the HTTP response headers. Again, from a blog post in 2007 by Nathan de Vries, we see this discussed. He followed up that blog post and discussion with his own comment:

Web 方面的唯一变化是较新版本的 Flash Player(当然是随 Flex 3 测试版提供的版本)现在支持 HTTPStatusEvent 实例的 responseHeaders 属性."

"The only change on the web front is that newer versions of the Flash Player (certainly those supplied with the Flex 3 beta) now support the responseHeaders property on instances of HTTPStatusEvent."

我希望这意味着它现在不是问题.

I'm hoping that means it is a non-issue now.

这篇关于使用 Flex 创建 REST 客户端是否可行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆