回答編集履歴
1
追記
test
CHANGED
@@ -1,3 +1,67 @@
|
|
1
1
|
変数`res`のスコープがおかしいですが、そこを直すと、Windows7+Ruby2.3で正常に実行できました。
|
2
2
|
|
3
3
|
`ca-bundle.crt`のファイル内容がおかしいと思われます。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
#追記
|
8
|
+
|
9
|
+
私がテストをしたときは、パスは自分の物に書き換えていたので気づきませんでしたが、単純なタイプミスですね。
|
10
|
+
|
11
|
+
```Ruby
|
12
|
+
|
13
|
+
puts '-'*80
|
14
|
+
|
15
|
+
require 'net/http'
|
16
|
+
|
17
|
+
require 'openssl'
|
18
|
+
|
19
|
+
require 'logger'
|
20
|
+
|
21
|
+
CERT_NOT_FOUND="CERT not found."
|
22
|
+
|
23
|
+
cert=File.expand_path(__FILE__+'\..\ca-bundle.crt')
|
24
|
+
|
25
|
+
raise CERT_NOT_FOUND if !File.exist?(cert)
|
26
|
+
|
27
|
+
ENV["SSL_CERT_FILE"] = File.expand_path(__FILE__+'\..\ca-bundle.crt') #<====ここ
|
28
|
+
|
29
|
+
url = URI.parse('https://google.jp/search')
|
30
|
+
|
31
|
+
puts url
|
32
|
+
|
33
|
+
req = Net::HTTP::Get.new(url.path)
|
34
|
+
|
35
|
+
http = Net::HTTP.new(url.host, url.port)
|
36
|
+
|
37
|
+
http.use_ssl = true
|
38
|
+
|
39
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
40
|
+
|
41
|
+
http.ca_file = ENV["SSL_CERT_FILE"]
|
42
|
+
|
43
|
+
res=nil
|
44
|
+
|
45
|
+
http.start {|http|
|
46
|
+
|
47
|
+
res = http.request(req)
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
puts res.body
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
本来はこう書いた方が良いでしょう。
|
58
|
+
|
59
|
+
```Ruby
|
60
|
+
|
61
|
+
File.expand_path(__FILE__+'\..\ca-bundle.crt')
|
62
|
+
|
63
|
+
↓
|
64
|
+
|
65
|
+
File.join(__dir__,'ca-bundle.crt')
|
66
|
+
|
67
|
+
```
|