草庐IT

post-content

全部标签

ruby - 尝试使用 ruby​​ Mechanize POST

我使用firefox插件LiveHTTPheaders捕获了登录HTTPheader。我找到了以下url和变量。POST/loginemail=myemail%40gmail.com&password=something&remember=1&loginSubmit=Login这是我正在运行的代码:require'rubygems'require'mechanize'browser=Mechanize.newbrowser.post('http://www.mysite.com/login',[["email","myemail%40gmail.com"],["password","s

ruby-on-rails - 在 Ruby 中发送 HTTP/2 POST 请求

我正在尝试使用新的ApplePushNotificationAPI,基于HTTP/2.我找到了http-2Rubygem,但文档并不清楚如何作为客户端发出请求。如何在Ruby/Rails中发出HTTP/2请求? 最佳答案 免责声明:我是下面列出的两个gem的作者。如果你想发出HTTP/2调用,你可以考虑NetHttp2,Ruby的HTTP/2客户端。同步调用的使用示例:require'net-http2'#createaclientclient=NetHttp2::Client.new("http://106.186.112.116

ruby-on-rails - 验证失败 : Upload file has an extension that does not match its contents

我正在使用回形针gem上传文件。我的回形针gem版本是paperclip-4.1.1。上传文件时抛出Validationfailed:Uploadfilehasanextensionthatdoesnotmatchitscontents.我正在尝试上传xlsx文件。而且我已经在模型content_type中提到了这一点。validates_attachment_content_type:upload_file,:content_type=>%w(application/mswordapplication/vnd.ms-officeapplication/vnd.ms-excelappl

ruby - Sinatra 请求 ["SOME_HEADER"] 不适用于 POST;文档错误?

Sinatra自述文件says:request["SOME_HEADER"]#valueofSOME_HEADERheader鉴于此应用:require'sinatra'post'/env'doenv['HTTP_X_FOO']endpost'/request'dorequest['X-Foo']endpost'/request_rack_http_format'dorequest['HTTP_X_FOO']end第一个规范通过;接下来的两个失败:describe"Sinatrashouldplacetheheaderin"dobefore(:all)doheader'X-Foo','

ruby - 如何让 Ruby 的 RestClient gem 在发布时尊重 content_type?

例如,在RestClient控制台中:RestClient.post'http://localhost:5001',{:a=>'b'},:content_type=>'application/json'这不会将application/json作为内容类型发送。相反,我看到:Content-Type:application/x-www-form-urlencoded我能够追踪到restclient/payload.rb的变化:classUrlEncoded'application/x-www-form-urlencoded'})endend用super替换super.merge会导致遵守

ruby-on-rails - 强制所有收到的请求 Content-Type 为 JSON

我实际上正在开发一个使用Rails4的API。如果客户端未在中指定媒体类型,我想将请求的Content-Type设置为JSONContent-Typeheader。为了获得这种行为,我尝试在我的ApplicationController中添加以下before_action:defset_request_default_content_typerequest.format=:jsonend在我的RegistrationsController#create方法中,我有一个断点来检查是否一切正常。嗯,request.format技巧不起作用,尽管值设置为application/json似乎C

ruby-on-rails - ActionDispatch::Http::UploadedFile.content_type 未在 Rspec 测试中初始化

背景:我有一个带有cover_file属性的Book模型,该模型通过我的一个RailsController使用上传的文件进行设置。我正在使用Railsv4.0.4。目标:我想测试只保存具有特定内容类型的文件。我计划使用设置了不同content_type属性的ActionDispatch::Http:UploadedFile对象创建Rspec测试示例。问题:当我用content_type初始化一个新的ActionDispatch::Http::UploadedFile时,它似乎没有被设置(请参阅下面的测试和输出,确认它为零)。看来我只能在UploadedFile初始化后用setter设置

ruby-on-rails - ruby rails : How would i stay on the same page if the post is not saved?

defcreate@addpost=Post.newparams[:data]if@addpost.saveflash[:notice]="Posthasbeensavedsuccessfully."redirect_toposts_pathelseflash[:notice]="Postcannotbesaved,pleaseenterinformation."endend如果帖子未保存,则会重定向到http://0.0.0.0:3000/posts,但我需要留在页面上,带有文本输入字段,以便用户可以输入数据。后模型classPosttruevalidates:content,:pr

ruby - 如何使用 HTTParty 实现此 POST 请求?

我在使用Ruby的HTTParty库向API端点发出POST请求时遇到困难。我正在与之交互的API是GittipAPI并且他们的端点需要身份验证。我已经能够使用HTTParty成功发出经过身份验证的GET请求。在示例代码中可以看到:user="gratitude_test"api_key="5962b93a-5bf7-4cb6-ae6f-aa4114c5e4f2"#Ihaveincludedrealcredentialssincetheaboveismerelyatestaccount.HTTParty.get("https://www.gittip.com/#{user}/tips.

ruby - Sinatra 中所有 POST 请求的前置过滤器?

有没有办法创建一个“之前”过滤器来捕获和预处理Sinatra中的所有POST请求? 最佳答案 执行此操作的一种方法是创建自定义condition在过滤器中使用:set(:method)do|method|method=method.to_s.upcasecondition{request.request_method==method}endbefore:method=>:postdoputs"pre-processPOST"end 关于ruby-Sinatra中所有POST请求的前置过滤