我有一个URL,我正在使用HTTP GET将查询传递到页面.最新的味道(in net/http)会发生什么,该脚本不会超出302响应.我尝试了几种不同的解决方案; HTTPClient,net/http,Rest-Client,Patron ......
我需要一种方法来继续到最后一页,以验证页面html上的属性标记.重定向是由于移动用户代理点击重定向到移动视图的页面,因此标题中的移动用户代理.这是我今天的代码:
require 'uri'
require 'net/http'
class Check_Get_Page
def more_http
url = URI.parse('my_url')
req, data = Net::HTTP::Get.new(url.path, {
'User-Agent' => 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5'
})
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
cookie = res.response['set-cookie']
puts 'Body = ' + res.body
puts 'Message = ' + res.message
puts 'Code = ' + res.code
puts "Cookie \n" + cookie
end
end …Run Code Online (Sandbox Code Playgroud) 我很难获得SSL来验证证书.我完全不了解证书是如何运作的,所以这是一个重大的障碍.这是运行脚本时出现的错误:
c:/Ruby191/lib/ruby/1.9.1/net/http.rb:611:in `connect': SSL_connect returned=1 e
rrno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL
::SSL::SSLError)
Run Code Online (Sandbox Code Playgroud)
这是相关的代码:
client = Savon::Client.new order_svc
request = client.create_empty_cart { |soap, http|
http.auth.ssl.cert_file = 'mycert.crt'
http.auth.ssl.verify_mode = :none
http.read_timeout = 90
http.open_timeout = 90
http.headers = { "Content-Length" => "0", "Connection" => "Keep-Alive" }
soap.namespaces["xmlns:open"] = "http://schemas.datacontract.org/2004/07/Namespace"
soap.body = {
"wsdl:brand" => brand,
"wsdl:parnter" => [
{"open:catalogName" => catalogName, "open:partnerId" => partnerId }
] }.to_soap_xml
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.