-3
所以說,我需要在vb.net中獲取頁面的URL,但唯一的方法是使用重定向。如何獲取頁面在vb.net中的URL重定向
像這樣: http://example.com/users/usertypeimg.php?id=1
重定向到: http://example.com/img/usertypemega.png
我怎麼會告訴重定向的終點是什麼(只獲取URL)
所以說,我需要在vb.net中獲取頁面的URL,但唯一的方法是使用重定向。如何獲取頁面在vb.net中的URL重定向
像這樣: http://example.com/users/usertypeimg.php?id=1
重定向到: http://example.com/img/usertypemega.png
我怎麼會告訴重定向的終點是什麼(只獲取URL)
的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
取決於您使用的框架。 – litelite
@litelite我正在使用.NET框架4.5.2 –
您應該閱讀[問]並參加[參觀]這不是問好問題(正如downvotes所證明的) – Plutonix