0
以下代碼將一些cookie數據作爲字符串返回。如何將此字符串轉換爲散列?
require 'httparty'
r = HTTParty.get('https://mijn.ing.nl/internetbankieren/SesamLoginServlet')
r.headers
# => {"date"=>["Sat, 26 Jul 2014 19:34:09 GMT"], "cache-control"=>["no-cache", "no-store"], "pragma"=>["no-cache"], "expires"=>["Thu, 01 Jan 1970 00:00:00 GMT"], "content-length"=>["13987"], "set-cookie"=>["sessiontype=mpb; Secure", "aac=742A83A50A4C422C24D6F952C4BF6355; Expires=Sun, 26 Jul 2015 19:34:08 GMT; Path=/; Domain=.ing.nl; Secure", "internetbankierenmi=1777182912.20480.0000; path=/", "TSdb640d=de34831032c17e8b66f123633372a9b341a9773368fccca553d402b1d4efbe89959deba9debace3fe0d47c86e27e0b6b1669bf05; Path=/"], "vary"=>["Accept-Encoding,User-Agent"], "content-type"=>["text/html;charset=ISO-8859-1"], "content-language"=>["en"], "connection"=>["close"], "strict-transport-security"=>["max-age=8640000"]}
response_cookies = r.headers['set-cookie']
# => "sessiontype=mpb; Secure, aac=742A83A50A4C422C24D6F952C4BF6355; Expires=Sun, 26 Jul 2015 19:34:08 GMT; Path=/; Domain=.ing.nl; Secure, internetbankierenmi=1777182912.20480.0000; path=/, TSdb640d=de34831032c17e8b66f123633372a9b341a9773368fccca553d402b1d4efbe89959deba9debace3fe0d47c86e27e0b6b1669bf05; Path=/"
我想給response_cookies
字符串轉換爲哈希我可以用POST請求一起發送。
它應該是這個樣子:
{
"sessiontype"=>"mpb",
"aac"=>"7430AEE30A4C42200A45ED316AA03490",
"Expires"=>"Sun, 26 Jul 2015 19:34:08 GMT",
"Path"=>"/",
"Domain"=>".ing.nl",
"internetbankierenmi"=>"1777182912.20480.0000",
"TSdb640d"=>"de34831032c17e8b66f123633372a9b341a9773368fccca553d402b1d4efbe89959deba9debace3fe0d47c86e27e0b6b1669bf05"
}
什麼是做到這一點的最好方法是什麼?
當我設置'headers'等於你的'r.headers'值,然後'response_cookies =標題[「SET- cookie']',我發現'response_cookies'是一個由四個字符串組成的數組,而不是一個字符串。請解釋或更正。爲什麼''Path'''「%2F」'的值?爲什麼'「path = /」'(小寫'「p」')沒有反映在你想要的結果中?將來,請不要只丟棄一堆數據。將問題修剪至其基本要素。而不是「TSdb640d = de ...」,接着是一個巨大的字符,你可以寫成,比如說「TSdb = d3」。請格式化,以免水平滾動。 –