20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/core_blur/util/request.rb', line 20
def Request.get(proxy_ip, proxy_port, url)
= {
"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36",
"Accept-Encoding" => "gzip"
}
options = {
:headers => ,
:http_proxyaddr => proxy_ip,
:http_proxyport => proxy_port
}
begin
response = HTTParty.get(url, options)
puts "响应状态码:#{response.code}"
if response.body.nil? || response.body.empty?
puts "page content: #{response.body}"
error = "请求失败,status code: #{response.code.to_s}"
puts "❌ #{error}"
Process.exit(-1)
else
return response
end
rescue => exception
puts "\n"
puts caller
puts "调用堆栈如上\n\n"
error = "请求失败, 请检查网络或参数是否正确:#{exception}"
puts "❌ #{error}"
Process.exit(-1)
end
end
|