2017-07-28 88 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