我似乎遇到使用curb(Ruby的卷曲程序)重定向302的问题
这是**不工作的代码片段**(它没有进行302重定向)
easy_options = {:follow_location => true, :enable_cookies => true, :useragent => 'curb', :cookiefile => 'cookie.txt'} multi_options = {:pipeline => true} url_fields = [ { :url => 'https://x.y.z/webapps/login/', :method => :post, :follow_location => true, :enable_cookies => true, :useragent => 'curb', :post_fields => { 'user_id' => 'xxxx', 'password' => 'xxxx', 'action' => 'login', 'encoded_pw' => Base64.strict_encode64('xxxx')}, } ] Curl::Multi.http(url_fields,{:pipeline => true}) do |easy, code, method| puts easy.header_str end
以下是似乎正常工作的代码段(它正在执行302重定向)
easy_options = {:follow_location => true, :enable_cookies => true, :useragent => 'curb', :cookiefile => 'cookie.txt'} multi_options = {:pipeline => true} url_fields = [ { :url => 'https://x.y.z/webapps/login/', :post_fields => { 'user_id' => 'xxxx', 'password' => 'yyyy', 'action' => 'login', 'encoded_pw' => Base64.strict_encode64('yyyy')}} ] Curl::Multi.post(url_fields, easy_options, multi_options) do|easy| # do something interesting with the easy response puts easy.last_effective_url end
问题:为什么第一个块没有按预期进行302重定向? :follow_location设置为true? 提前谢谢!
如果您需要更多信息,请告诉我