0

我正在尝试通过以下方式在 flex 和 rails 之间进行更新:

// TODO Auto-generated method stub
var strXml:XML = <test>
<test_id>{txtMarketId.text}</test_id>
<market_name>{txtMarketName.text}</market_name>
</test>;

req = new URLRequest("http://localhost:3000/tests/"+market_id);
jrwloader  = new URLLoader();
params = new URLVariables();
req.data = strXml.toString();                               
req.method = URLRequestMethod.POST;                                                         
req.requestHeaders.push(new URLRequestHeader("X-HTTP-Method-Override", URLRequestMethod.PUT));                                                          
jrwloader.load(req);

在我的 Rails 应用程序中,我得到了这个:

Started PUT "/markets/2" for 10.10.10.10 at 2012-09-08 18:37:24 +0000
Processing by TestController#update as */*
  Parameters: {"test_id:2, market_name:test"=>nil, "id"=>"2"}
WARNING: Can't verify CSRF token authenticity
  Market Load (0.2ms)  SELECT `tests`.* FROM `test` WHERE `test`.`test_id` = 2 LIMIT 1
   (0.1ms)  BEGIN
   (0.1ms)  COMMIT
Redirected to http://localhost:3000/tests/2
Completed 302 Found in 3ms (ActiveRecord: 0.4ms)

我想我已经接近答案了,但我无法将新数据设置到数据库中。

4

2 回答 2

0

您应该将 CSRF 令牌添加到您的请求中。

这是有关该主题的更多信息:http: //guides.rubyonrails.org/security.html#cross-site-request-forgery-csrf

于 2012-09-08T22:12:03.770 回答
0

我解决它!主要问题只是在我的请求中添加一行。所以最后我得到了这样的东西:

req = new URLRequest("http://localhost:3000/tests/"+market_id);
jrwloader  = new URLLoader();
params = new URLVariables();
req.data = strXml.toString();                               
req.method = URLRequestMethod.POST;                                                         
req.requestHeaders.push(new URLRequestHeader("X-HTTP-Method-Override", URLRequestMethod.PUT));                                                          
**req.requestHeaders.push(new URLRequestHeader("Content-type", 'application/xml'));**         jrwloader.load(req);

谢谢大家!

于 2012-09-12T00:16:10.363 回答