从 Flex 应用程序向 Ruby on Rails 后端发送 post 请求时出现问题

发布于 2024-07-18 02:12:33 字数 899 浏览 6 评论 0原文

我无法让我的 Flex 应用程序向我的 Rails 应用程序发送 POST 请求。 似乎总是发送GET。

这是我的服务声明:

<mx:HTTPService id="add_email_service" showBusyCursor="true" result="parseJoinResult();" fault="onJoinFault(event)" useProxy="false" />

在我的应用程序 init 函数中,我将方法设置为 POST:

add_email_service.url = join_url;
add_email_service.method = "POST";

但是,当我发送该请求时,我的 Rails 应用程序仍然将该请求视为 post 请求。 我知道这一点是因为如果我要求请求在我的routes.rb文件中进行POST:

# RESTful API for joining a mailing list
  map.connect 'mailing_lists/join/:id', 
      :controller => 'mailing_lists', 
      :action => 'join', 
      :conditions => { :method => :post}

请求错误,我可以在我的开发日志中看到:

“Processing ApplicationController#index(for 127.0.0.1 at 2009-04-23 14:25) :35) [获取], ActionController::MethodNotAllowed(仅允许发布请求。):"

有谁知道为什么会发生这种情况?

I am having trouble getting my flex app to send a POST request to my Rails app. It seems to always send GET.

This is my service declaration:

<mx:HTTPService id="add_email_service" showBusyCursor="true" result="parseJoinResult();" fault="onJoinFault(event)" useProxy="false" />

In my application init function, I set the method to POST:

add_email_service.url = join_url;
add_email_service.method = "POST";

However, my Rails app still sees the request as a post request when I send it. I know this because if I require the request to be POST in my routes.rb file:

# RESTful API for joining a mailing list
  map.connect 'mailing_lists/join/:id', 
      :controller => 'mailing_lists', 
      :action => 'join', 
      :conditions => { :method => :post}

the request faults and I can see in my dev log :

"Processing ApplicationController#index (for 127.0.0.1 at 2009-04-23 14:25:35) [GET],
ActionController::MethodNotAllowed (Only post requests are allowed.):"

Does anyone know why this is happening?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

源来凯始玺欢你 2024-07-25 02:12:33

如果没有发送变量,旧版本的 Flash Player(在某些浏览器中)会自动将您的请求从 POST 切换为 GET。

尝试在您的请求中添加一个参数,看看是否可以解决问题。

将 Flash Player 与 Restful Rails 集成?

还要为其他一些问题做好准备:

  1. Flash Player 只能接受 HTTP 状态代码 200,其他所有情况都会引发异常并阻止您获取消息正文。
  2. 您无法发送 PUTS 或 DELETE HTTP 方法

Older versions of the Flash Player (in some browsers) would automatically switch your request from POST to GET if there were no variables being sent.

Try adding a param to your request and see if that fixes it.

Integrating Flash Player with Restful Rails?

Get ready for some other issues too:

  1. The Flash Player can only accept HTTP status code of 200, everything else throws an exception and prevents you from getting at the message body.
  2. You can't send PUTS or DELETE HTTP methods
雄赳赳气昂昂 2024-07-25 02:12:33

我相信实际上只有200。

I believe it's literally 200 only.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文