Get redirect of a URL in Ruby

后端 未结 7 1274
盖世英雄少女心
盖世英雄少女心 2020-12-02 23:18

According to Facebook graph API we can request a user profile picture with this (example):

https://graph.facebook.com/1489686594/picture

Bu

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 23:47

    You can use Net::Http and read the Location: header from the response

    require 'net/http'
    require 'uri'
    
    url = URI.parse('http://www.example.com/index.html')
    res = Net::HTTP.start(url.host, url.port) {|http|
      http.get('/index.html')
    }
    res['location']
    

提交回复
热议问题