2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

書籍『Ruby on Rails 5 超入門』【6章】ajax Yahoo!ニュースのヘッドライン RSSエラー

Last updated at Posted at 2017-06-27

書籍通りに作成すると次のエラーが発生します。

REXML::ParseException (Missing end tag for 'meta' (got "head")

原因

http → https になっている

コード修正前
書籍

require 'net/http'

def index
end

def data
	url = URI('http://news.yahoo.co.jp/pickup/sports/rss.xml')
	http = Net::HTTP.new(url.host)
	response = http.get(url)
	@data = Hash.from_xml(response.body).to_json.html_safe
	logger.info @data
end

コード修正後

  require 'net/https'
  def index
  end

def data
	url = URI('https://news.yahoo.co.jp/pickup/sports/rss.xml')
	https = Net::HTTP.new(url.host,443)
	https.use_ssl = true
	https.verify_mode = OpenSSL::SSL::VERIFY_NONE //証明書を検証しない
	https.verify_depth = 5
	response = https.get(url)
	@data = Hash.from_xml(response.body).to_json.html_safe
	logger.info @data
	
end
2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?