我正在开发一个类似 api 的应用程序,它允许其他应用程序发送请求,这些请求会在类似 api 的应用程序中触发一系列操作。我需要找到一种通过 url 发送大参数(嵌入代码)的方法。我正在使用 Sinatra。
我的第一次尝试:(不起作用,因为嵌入代码不是可接受的 url 参数)
get '/grab/:name/:bucket/:embed_code' do
@video = Video.create(
:name => params[:name],
:bucket => params[:bucket],
:embed_code => params[:embed_code],
:created_at => Time.now
)
redirect "/video/#{@video.id}"
end
我的第二次尝试:(Connection refused - connect(2) (Errno::ECONNREFUSED)
错误)
# (get '/video_form') points to (post '/video') and post_form was supposed to trigger it
get '/video_form' do
erb :new_video
end
post '/video' do
@video = Video.create(
:name => params[:name],
:bucket => params[:bucket],
:embed_code => params[:embed_code],
:created_at => Time.now
)
redirect "/video/#{@video.id}"
end
Net::HTTP.post_form(URI.parse('http://localhost:4567/video_form'),{'name'=>'example_2', 'bucket' => 'bucket_name', 'embed_code' => '<iframe width="560" height="315" src="http://www.youtube.com/embed/ncL1UlvjiMQ" frameborder="0" allowfullscreen></iframe>'})