rubyã§ã¯æ¨æºã©ã¤ãã©ãªã§ãããnet/httpããå©ç¨ãããã¨ã§ãç°¡åã«webãµã¼ãã¸ã®ãªã¯ã¨ã¹ãã®å®è¡ã»ã¬ã¹ãã³ã¹ã®åå¾ãè¡ãã¾ãã
url = "http://hogehoge.com?p1=aaaaa&p2=ãã¹ã" #URI.escapeã¯ãã«ããã¤ãæåçãã¨ã¹ã±ã¼ããã escape_url = URI.escape(url) #=>http://hogehoge.com?p1=aaaaa&p2=%E3%83%86%E3%82%B9%E3%83%88 #URI.parseã¯URI::Genericã¤ã³ã¹ã¿ã³ã¹ãè¿ããããã¯ä¸ããããURIãããã¹ãåããã¼ãããã¹çã®ã¡ã³ãã¼ãæã¤ã response = Net::HTTP.get_response(URI.parse(escape_url)) #ã¬ã¹ãã³ã¹ã®å 容ã¯response.bodyã§åå¾ã§ããã puts response.body #=><html><head>â¦</head><body>â¦</body></html>
ã¨ããããhttpsã§æ¥ç¶ããã¨ä»¥ä¸ã®ãããªãOpenSSL::SSL::SSLErrorããçºçãããã¨ãããã¾ãã
url = "https://hogehoge.com?p1=aaaaa&p2=ãã¹ã" escape_url = URI.escape(url) response = Net::HTTP.get_response(URI.parse(escape_url)) #=> `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
åå ã¯Net::HTTPã¢ã¸ã¥ã¼ã«ãã¯ã©ã¤ã¢ã³ãå´ã®SSL証ææ¸ãè¦ã¤ãããããæ¥ç¶å ãµã¼ãã®å®å ¨æ§ã確èªã§ããªãããã®ããã§ãã
ããããSSL証ææ¸ãç¡ãã£ã¦ã©ããããã¨ï¼ ã¨ããã®ã¯ãã¡ããã覧ãã ããã
qiita.com
解決æ¹æ³
解決ããæ¹æ³ã¯ã以ä¸ã®ï¼ã¤ã
- ã¯ã©ã¤ã¢ã³ãã®SSL証ææ¸ãå°å ¥ããã
- æ¥ç¶å ãµã¼ãã®å®å ¨æ§ã確èªããã¨ã«ããæ¥ç¶ããã
ä»åã¯ãæã£åãæ©ãããªã®ã§ã2ã¤ãã®æ¹æ³ãç´¹ä»ãã¾ãã
æ¥ç¶å ãµã¼ãã®å®å ¨æ§ã確èªããã¨ã«ããæ¥ç¶ããã
url = "https://hogehoge.com?p1=aaaaa&p2=ãã¹ã" escape_url = URI.escape(url) uri = URI.parse(escape_url) #è¨å®ãå¿ è¦ãªããNet::HTTPã¤ã³ã¹ã¿ã³ã¹ãçæããã http = Net::HTTP.new(uri.host,uri.port) #ã¹ãã¼ã ã«httpsãå©ç¨ http.use_ssl=true #ããããã¤ã³ããæ¥ç¶å ãµã¼ãã®è¨¼ææ¸ãæ¤è¨¼ã§ããªãã¦ãæ¥ç¶ããã http.verify_mode=OpenSSL::SSL::VERIFY_NONE #getã¡ã½ããã«ã¯ãªã¯ã¨ã¹ãURIãæå®ããã #uri.request_uri => /?p1=aaaaa&p2=%E3%83%86%E3%82%B9%E3%83%88 response = http.get(uri.request_uri)
ã¯ã©ã¤ã¢ã³ãã«SSL証ææ¸ãå°å ¥ããããã«ã¯
ãã¡ãã®ãã¼ã¸ããåç
§ãã ããã
d.hatena.ne.jp
ãã¼ãã§ã¯ãRuby (PERFECT SERIES 6)
- ä½è : Rubyãµãã¼ã¿ã¼ãº,ããããã¾ãã®ã,寺ç°ç太é,ä¸æçé,è¿è¤å®æºæ,æ©ç«åå®,é¢å£äº®ä¸
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2013/08/10
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (22件) ãè¦ã