Z
Zouplaz
I'm trying to fetch an url which needs several cookies to be set in
order to properly return a result.
I've found a page in the website from which I can get the session
cookies (instead of posting cookies set by myself I prefer use the ones
coming from the server)
So,
def http_get(url, url_before = nil)
headers = Hash.new()
headers['User-agent'] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows
NT 5.1)"
unless url_before.nil?
response = @http.get(url_before)
cookies = response.response['set-cookie']
headers['Cookie'] = cookies
end
response = @http.get(url, headers)
raise "url #{url} not accessible on host #{@host}:#{@port} - code
#{response.code}" if not ['200','302'].include?(response.code)
response.body
end
The problem is that I'm not sure it the way I repost the cookies is
right or not. The cookies retrieved by the unless block ARE OK but when
the second @http.get occurs, the remote web server ignore them and send
a redirect to a default page.
So, I need to be sure that I send cookies properly in the GET request
before investigating the cookies's content
Thanks for your help
Note : when rewiewing this post I think I should write some code to keep
the cookies's content between two calls (as a browser do) instead of
handling things the way I do. But it's juste a side note
order to properly return a result.
I've found a page in the website from which I can get the session
cookies (instead of posting cookies set by myself I prefer use the ones
coming from the server)
So,
def http_get(url, url_before = nil)
headers = Hash.new()
headers['User-agent'] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows
NT 5.1)"
unless url_before.nil?
response = @http.get(url_before)
cookies = response.response['set-cookie']
headers['Cookie'] = cookies
end
response = @http.get(url, headers)
raise "url #{url} not accessible on host #{@host}:#{@port} - code
#{response.code}" if not ['200','302'].include?(response.code)
response.body
end
The problem is that I'm not sure it the way I repost the cookies is
right or not. The cookies retrieved by the unless block ARE OK but when
the second @http.get occurs, the remote web server ignore them and send
a redirect to a default page.
So, I need to be sure that I send cookies properly in the GET request
before investigating the cookies's content
Thanks for your help
Note : when rewiewing this post I think I should write some code to keep
the cookies's content between two calls (as a browser do) instead of
handling things the way I do. But it's juste a side note