2017-11-22 4 views
1

maxRedirects = 5のアキシャスを使用すると、別のURLにリダイレクトされるURLを入力すると、最終的なランディングページからURLを取得するにはどうすればよいですか? HTTPヘッダーでは、200コードがある場合、ランディングページのヘッダーフィールドはありません。リダイレクト後にランディングページURLをアキシャルで使用する方法

例:私は

axios.get('http://stackoverflow.com/',config) 
.then(function(response) { console.log(response);} 

を使用する場合、それはhttps://stackoverflow.comにリダイレクトされます。最終的なURL値「https://stackoverflow.com」を取得するにはどうすればよいですか?

私は応答で調査し、完全なURLを再作成する必要がありますか?

答えて

0

ここに私のクイックで汚れた解決策があります。開始URLはhttp://www.stackoverflow.com/questions/47444251/how-to-get-the-landing-page-url-after-redirections-using-axios、最終的なリンク先URLはhow to get the landing page URL after redirections using axiosです。リンク先URLを取得するには、下記の手順をご覧ください。

axios.get('http://www.stackoverflow.com/questions/47444251/how-to-get-the-landing-page-url-after-redirections-using-axios').then(function(response) { 
     console.log(response.request.res.req.agent.protocol+"//"+response.request.res.connection._host+response.request.path); 
    }).catch(function(no200){ 
     console.error("404, 400, and other events"); 
    console.log(no200.request.res.req.agent.protocol+"//"+no200.request.res.connection._host+no200.request.path); 
    }); 
関連する問題