Class: PM::Network
- Inherits:
-
Object
- Object
- PM::Network
- Defined in:
- lib/cocoapods-byte-panglem-beta/net.rb
Overview
网络请求
Class Method Summary collapse
-
.post(url, body) ⇒ Object
post请求.
- .request_adapter(body, is_debug = false) ⇒ Object
- .request_track(body, version_code) ⇒ Object
Class Method Details
.post(url, body) ⇒ Object
post请求
13 14 15 16 17 18 19 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 |
# File 'lib/cocoapods-byte-panglem-beta/net.rb', line 13 def Network.post (url,body) # puts "start net request:#{body}" uri = URI.parse(url) https = Net::HTTP.new(uri.host,uri.port) https.use_ssl = true ## 正式时请打开 https.verify_mode = OpenSSL::SSL::VERIFY_PEER https.cert_store = OpenSSL::X509::Store.new https.cert_store.set_default_paths # 核心:自定义验证回调,跳过 CRL 错误 https.verify_callback = lambda do |preverify_ok, ssl_context| # 仅保留证书有效性验证,忽略 CRL 相关错误(preverify_ok 为 true 即通过) preverify_ok end request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) # request["Cookie"]="__union_admin_sess_cookie=232301_noduimkpdwrbyrkr1qih; _ssa_userphone=; _ssa_username=zhangtianhao.1230" request.body = body.to_json if PM::Recorder.instance.is_debug puts "[cocoapods-byte-panglem-beta][debug] 网络请求信息: #{body.to_json}, url:#{url}" end res = https.request(request) if res.code == "200" data = JSON.parse(res.body) if PM::Recorder.instance.is_debug puts "[cocoapods-byte-panglem-beta][debug] 网络返回信息: #{data}" end return data else ## 网络请求异常的提示 puts "[cocoapods-byte-panglem-beta][error] response code = #{res.code}, message = #{res.}" end nil end |
.request_adapter(body, is_debug = false) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cocoapods-byte-panglem-beta/net.rb', line 50 def Network.request_adapter(body, is_debug = false) if false url = URI.parse('http://localhost:8080/index.html') http = Net::HTTP.new(url.host, url.port) request = Net::HTTP::Get.new(url.path, initheader = {'Content-Type' =>'application/json'}) response = http.request(request) if PM::Recorder.instance.is_debug puts "[cocoapods-byte-panglem-beta][debug] 网络请求信息: #{body.to_json}, url:#{url}" end data = JSON.parse(response.body) if PM::Recorder.instance.is_debug puts "[cocoapods-byte-panglem-beta][debug] 网络返回信息: #{data}" end data else data = post("https://open-api.pangleglobal.com/union/media/open_api/auto_upgrade/config",body) end end |
.request_track(body, version_code) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/cocoapods-byte-panglem-beta/net.rb', line 70 def Network.request_track(body, version_code) ## https://api16-access-sg.pangle.io/api/ad/union/sdk/stats/batch/ url = "https://api16-access-sg.pangle.io/api/ad/union/sdk/stats/batch/"+"?aid=5000546&version_code=#{version_code}&device_platform=iphone" data = post(url,body) data end |