我想对POST request我的本地开发者这样做:
HTTParty.post('http://localhost:3000/fetch_heroku',
:body => {:type => 'product'},)
Run Code Online (Sandbox Code Playgroud)
但是,它从服务器控制台报告
Started POST "/fetch_heroku" for 127.0.0.1 at 2016-02-03 23:33:39 +0800
ActiveRecord::SchemaMigration Load (0.0ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by AdminController#fetch_heroku as */*
Parameters: {"type"=>"product"}
Can't verify CSRF token authenticity
Completed 422 Unprocessable Entity in 1ms
Run Code Online (Sandbox Code Playgroud)
这是我的控制器和路线设置,非常简单.
def fetch_heroku
if params[:type] == 'product'
flash[:alert] = 'Fetch Product From Heroku'
Heroku.get_product
end
end
post 'fetch_heroku' => 'admin#fetch_heroku'
Run Code Online (Sandbox Code Playgroud)
我不确定我需要做什么?关闭CSRF肯定会起作用,但我认为在创建这样的API时应该是我的错误.
我还需要做其他设置吗?
当我尝试POST时RestKit,Rails控制台中有一个警告:
Started POST "/friends" for 127.0.0.1 at 2012-04-16 09:58:10 +0800
Processing by FriendsController#create as */*
Parameters: {"friend"=>{"myself_id"=>"m001", "friend_id"=>"f001"}}
WARNING: Can't verify CSRF token authenticity
(0.1ms) BEGIN
SQL (1.7ms) INSERT INTO `friends` (`friend_id`, `myself_id`) VALUES ('f001', 'm001')
(1.1ms) COMMIT
Redirected to http://127.0.0.1:3000/friends/8
Completed 302 Found in 6ms (ActiveRecord: 3.0ms)
Run Code Online (Sandbox Code Playgroud)
这是客户端代码:
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject: @"f001" forKey: @"friend_id"];
[attributes setObject: @"m001" forKey: @"myself_id"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:attributes forKey:@"friend"];
[[RKClient sharedClient] post:@"/friends" params:params delegate:self];
Run Code Online (Sandbox Code Playgroud)
我该如何摆脱警告?
我正在使用devise(最新版本 - 3.2.0)rails(最新版本 - 4.0.1)
我正在进行简单的身份验证(没有ajax或api)并且收到CSRF真实性令牌的错误.检查下面的POST请求
started POST "/users/sign_in" for 127.0.0.1 at 2013-11-08 19:48:49 +0530
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"?",
"authenticity_token"=>"SJnGhXXUXjncnPhCdg3muV2GYCA8CX2LVFV78pqddD4=", "user"=>
{"email"=>"a@a.com", "password"=>"[FILTERED]", "remember_me"=>"0"},
"commit"=>"Sign in"}
Can't verify CSRF token authenticity
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."email" =
'a@a.com' LIMIT 1
(0.1ms) begin transaction
SQL (0.4ms) UPDATE "users" SET "last_sign_in_at" = ?, "current_sign_in_at" = ?,
"sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = 2 [["last_sign_in_at", Fri,
08 Nov 2013 …Run Code Online (Sandbox Code Playgroud) 我在Ruby上运行我的Rails后端,我想将数据发布到此服务器.但如果我用PAW做一个Post-request,我会被重定向.我是Http Requests的新手.有人可以解释我的功能以及如何使用http post请求吗?
我想在我的服务器的datanase(sqlite3)上发布信息.
这是如何运作的?请解释:)谢谢.问候约翰
这是代码:
OwnersController:
#app/controllers/owners_controller.rb
class OwnersController < SessionsController
respond_to :html
before_action :owner_find, only: [:show, :edit, :update, :destroy]
def index
@owners = Owner.all
end
def show
end
def update
@owner = Owner.find(params[:id])
if @owner.update(owner_params)
redirect_to @owner
else
render 'edit'
end
end
def new
@owner = Owner.new
end
def destroy
@owner.destroy
redirect_to owners_path
end
def edit
end
def create
@owner = Owner.new owner_params
if @owner.save!
flash[:notice] = 'You signed up successfully'
flash[:color]= 'valid'
redirect_to owners_path
else
flash[:notice] …Run Code Online (Sandbox Code Playgroud)