2017-07-28 92 views
-3

所以說,我需要在vb.net中獲取頁面的URL,但唯一的方法是使用重定向。如何獲取頁面在vb.net中的URL重定向

像這樣: http://example.com/users/usertypeimg.php?id=1

重定向到: http://example.com/img/usertypemega.png

我怎麼會告訴重定向的終點是什麼(只獲取URL)

+0

取決於您使用的框架。 – litelite

+0

@litelite我正在使用.NET框架4.5.2 –

+0

您應該閱讀[問]並參加[參觀]這不是問好問題(正如downvotes所證明的) – Plutonix

回答

0

HttpClient類將自動重定向對於你來說,所有你需要做的就是發送一個GET消息到原始URL,然後從響應中讀取實際的重定向URL:

Public Async Function GetRedirectedUrl(originalUrl As String) As Threading.Tasks.Task(Of String) 
    Dim client As New HttpClient() 
    Dim response As HttpResponseMessage = Await client.GetAsync("http://example.com/users/usertypeimg.php?id=1") 
    Return response.Headers.Location.ToString() 
End Function