我正在尝试使用ruby中的Net::HTTP来使用Google Docs List Data API 3.0版,使用的代码如下。
require 'net/http'
spreadsheets_uri = 'http://spreadsheets.google.com/feeds/spreadsheets/private/full'
docs_uri = "https://docs.google.com/feeds/default/private/full?v=3"
def get_feed(uri, headers=nil)
uri =
我试图使用ruby Net::HTTP.get为网站做http get,但是我得到了一个错误代码512。我试着用ssl为url "“做一个get。它只是在没有ssl的情况下重定向到url。
代码如下:
uri = URI('https ://www.shopyourway.com') #space between https and : does not exist
body = Net::HTTP.get(uri)
我可以用浏览器浏览网址。但是为什么我不能为这个url做http get呢?
谢谢
我尝试使用ruby根据帐户1234进行搜索,但不断收到SSL_connect returned=1 errno=0证书错误。该站点已经签名,但出于某种原因,Ruby不喜欢它。证书已正确签名,所以我不确定它为什么要拒绝它。
require 'net/http'
uri = URI("https://secure.domain.com/api/account/1234?api_key"+key)
response = Net::HTTP.get(uri)
puts response.body #this must show the JSON contents
基于
我想让我的一个控制器从我的控制器中发出一个http请求,以“获取”并解析一个xml,然后我可以在我的视图中显示这个请求。听起来是个简单的任务。
require 'net/http'
class Profile::EventTypesController < ProfileController
def index
url = URI.parse('instagram.com')
req = Net::HTTP.new(url, 80)
res = req.get('/my_account')
xml
使用Ruby,我想检查一个图像,看看它是否可热链接。我拥有的代码在许多情况下都可以工作,但有时不能。
代码:
class Hotlinkable
def self.is_hotlinkable? url
return if url.blank?
begin
res = get_response_with_redirect URI.parse(url)
res.code == '200'
rescue => e
puts e.inspect
我有一个Ruby代码: require 'net/http'
url = "https://stackoverflow.com/questions/65798852/how-do-i-set-an-electron-variable-at-compile-time"
response = Net::HTTP.get_response(url, '/') 这会产生错误: getaddrinfo: nodename nor servname provided, or not known (SocketError) 和 Failed to open
现在,我在ruby中做一个简单的GET请求时遇到了这个错误消息: #<SocketError: Failed to open TCP connection to api.github.com:443 (getaddrinfo: nodename nor servname provided, or not known)> 这是我的ruby代码: require 'uri'
require 'net/http'
class RequestDouble
def initialize(endpoint)
@endpoint = endpoin
我的代码就在这里:
// get host name from URL
preg_match('@^(?:http://)?([^/]+)@i',
"http://www.joomla.subdomain.php.net/index.html", $matches);
$host = $matches[1];
// get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo
要在不使用阻止表单的情况下执行Net::HTTP https请求,您可以执行以下操作:
...
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
...
但是,有没有办法告诉Net::HTTP在执行块形式时使用https?
u = URI.parse(url)
Net::HTTP.start(u.host, u.port) do |http|
# if I put http.use_ssl = true here, ruby complains that this can't
# be done becua
我在Ruby on rails项目中有如下代码,用于从非rails API获取HTTP响应
app/model/rest_api.rb
require "uri"
require "net/https"
require "net/http"
require "active_support"
class RestApi
# the URL for the Twitter Trends endpoint
@url = 'http://api.twitter.com/1/trends.json'
def s
我使用了的示例,它只是在回调阶段出现了问题。我还测试了其他一些样本,结果都是一样的。
Started GET "/auth/facebook/callback?state=118c21d7ea5675990e0a5e8a876f041f59dbc9a925f94754&code=AQDp93hH-WQor4ZQ8S_ZIGw0dTARw5vPMmkNAiRW9Ql8n7-fny0R5Du88InAILPbXUmdwWh_MyMpZzHzhO2YSlDXeMclSdyDfQQbtlFqixnYgpFt_3Sx5DETKIAYj2amRhK6JaNvxT1ffXgJ6qbMfHUb