草庐IT

HTTP_IF_NONE_MATCH

全部标签

ruby-on-rails - Ruby NET::HTTP 在主体之前读取 header (没有 HEAD 请求)?

我使用Net::HTTP和Ruby来抓取URL。我不想抓取流式音频,例如:http://listen2.openstream.co/334其实我只想抓取Html内容,所以没有pdfs、video、txt..现在,我将open_timeout和read_timeout都设置为10,所以即使我抓取这些流式音频页面,它们也会超时。url='http://listen2.openstream.co/334'path=uri.pathreq=Net::HTTP::Get.new(path,{'Accept'=>'*/*','Content-Type'=>'text/plain;charset=u

ruby - `open_http' : 403 Forbidden (OpenURI::HTTPError) 字符串 "Steve_Jobs"但不是任何其他字符串

我正在学习http://ruby.bastardsbook.com/提供的Ruby教程我遇到了以下代码:require"open-uri"remote_base_url="http://en.wikipedia.org/wiki"r1="Steve_Wozniak"r2="Steve_Jobs"f1="my_copy_of-"+r1+".html"f2="my_copy_of-"+r2+".html"#readthefirsturlremote_full_url=remote_base_url+"/"+r1rpage=open(remote_full_url).read#writeth

ruby - 安装 RDoc 文档时出错 : incompatible encoding regexp match

上周,在一些gem安装或gem更新操作中,我收到了与这些类似的错误:ERROR:Whilegeneratingdocumentationforsinatra-1.3.1...MESSAGE:errorgeneratingC:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/doc/sinatra-1.3.1/rdoc/README_de_rdoc.html:incompatibleencodingregexpmatch(UTF-8regexpwithIBM437string)(Encoding::CompatibilityError)类似的:E

ruby - 如何在使用 Ruby 的 OpenUri 下载之前获取 HTTP header

我目前正在使用OpenURI下载Ruby中的文件。不幸的是,如果不下载完整文件,似乎不可能获得HTTPheader:open(base_url,:content_length_proc=>lambda{|t|ift&&0t)end},:progress_proc=>lambda{|s|pbar.progress=sifpbar}){|io|putsio.sizeputsio.meta['content-disposition']}运行上面的代码表明它首先下载了完整的文件,然后才打印我需要的标题。有没有办法在下载完整文件之前获取header,以便在header与我预期的不同时取消下载?

ruby - Heroku 上 Rack::Static 应用程序的 HTTP 基本身份验证

我在Heroku上托管了一个简单的Rack应用程序。配置.ru:useRack::Static,:urls=>["/stylesheets","/images","/javascripts"],:root=>"public"runlambda{|env|[200,{'Content-Type'=>'text/html','Cache-Control'=>'public,max-age=86400'},File.open('public/index.html',File::RDONLY)]}如何向其中添加HTTP基本身份验证?如果它只适用于生产环境,则加分。谢谢

ruby-on-rails - 添加内联类 if ...(在 1 行中)

我想将一个类添加到一个link_to只有当一个陈述为真时。"last"ifproduct==@products.last%>IF语句影响整行而不仅仅是:class部分的问题。我知道我可以用IFELSE完成它,但是是否可以在一行中完成它? 最佳答案 (product==@products.last?"last":"")%> 关于ruby-on-rails-添加内联类if...(在1行中),我们在StackOverflow上找到一个类似的问题: https://s

ruby - 在 ruby​​ 中访问 Net::HTTP::Post 的 header

我有以下代码:uri=URI.parse("https://rs.xxx-travel.com/wbsapi/RequestListenerServlet")https=Net::HTTP.new(uri.host,uri.port)https.use_ssl=truereq=Net::HTTP::Post.new(uri.path)req.body=searchxmlreq["Accept-Encoding"]='gzip'res=https.request(req)这通常工作正常,但另一端的服务器提示我的XML中的某些内容,那里的技术人员需要xml消息和正在发送的header。我收

ruby - 如何将 Net::HTTP 响应转换为 Ruby 1.9.1 中的特定编码?

我有一个Sinatra应用程序(http://analyzethis.espace-technologies.com)执行以下操作检索HTML页面(通过net/http)从response.body创建一个Nokogiri文档提取一些信息并在响应中发回。响应应采用UTF-8编码所以我在尝试阅读使用windows-1256编码的网站(如www.filfan.com或www.masrawy.com)时遇到了问题。问题是编码转换的结果不正确,虽然没有抛出错误。net/httpresponse.body.encoding给出了ASCII-8BIT,无法转换为UTF-8如果我执行Nokogiri

ruby-on-rails - Ruby:IF 语句中的 Nils

这个问题在这里已经有了答案:HowtoavoidNoMethodErrorformissingelementsinnestedhashes,withoutrepeatednilchecks?(16个答案)关闭7年前。我正在处理的Rails应用程序中有以下非常难看的ruby​​代码:ifparams.present?ifparams[:search].present?ifparams[:search][:tags_name_in].present?...endendend我想问的是params[:search][:tags_name_in]是否已经定义,但是因为params、params

ruby-on-rails - 通过 Ruby 的 HTTP post 请求

我是ruby​​的新手,正在尝试一些基本的东西。当我使用以下命令向服务器发送HTTP请求时:curl-v-H"Content-Type:application/json"-XGET-d"{"myrequest":"myTest","reqid":"44","data":{"name":"test"}}"localhost:8099我的服务器将JSON数据视为"{myrequest:myTest,reqid:44,data:{name:test}}"但是当我使用以下ruby​​代码发送请求时:require'net/http'@host='localhost'@port='8099'@p