Created
September 19, 2012 05:23
-
-
Save honda0510/3747841 to your computer and use it in GitHub Desktop.
リダイレクト先のURLを取得 http://www.moug.net/faq/viewtopic.php?t=64316
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
' 参照設定 | |
' Microsoft XML, v6.0 | |
Sub test() | |
Debug.Print getLocation("http://nec.www.yahoo.co.jp") | |
End Sub | |
Function getLocation(url As String) As String | |
Dim url2 As String | |
With New MSXML2.ServerXMLHTTP60 | |
.Open "HEAD", url, False | |
.Send | |
url2 = .getOption(SXH_OPTION_URL) | |
End With | |
If url <> url2 Then | |
getLocation = url2 | |
End If | |
End Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
' 参照設定 | |
' Basp21 1.0 Type Library | |
Sub test() | |
Debug.Print getLocation("nec.www.yahoo.co.jp") | |
End Sub | |
Function getLocation(domain As String) As String | |
Dim Socket As BASP21Lib.Socket | |
Dim Result As Long | |
Dim RequestHeader As String | |
Dim Line As Variant | |
Set Socket = New BASP21Lib.Socket | |
Result = Socket.Connect(domain, 80, 10) | |
If Result <> 0 Then | |
Err.Raise Result, , "Connection Error1" | |
End If | |
RequestHeader = _ | |
"HEAD / HTTP/1.1" & vbCrLf & _ | |
"Host: " & domain & vbCrLf & _ | |
vbCrLf | |
Result = Socket.Write(RequestHeader) | |
If Result <> 0 Then | |
Err.Raise Result, , "Connection Error2" | |
End If | |
Do | |
Result = Socket.ReadLine(Line) | |
If Result = 0 And Len(Line) Then | |
If Line Like "Location: *" Then | |
getLocation = Replace(Line, "Location: ", "", Count:=1) | |
Exit Do | |
End If | |
Else | |
Exit Do | |
End If | |
Loop | |
Socket.Close | |
End Function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BASP21を使ってリダイレクト先を取得してみました。 | |
■経緯 | |
telnetを使えばいいだろう | |
↓ | |
telnetを自動化するにはどうしたら | |
↓ | |
BASP21ソケットオブジェクトでTCP/IP通信ができるらしい | |
↓ | |
できた | |
■要インストール | |
BASP21 DLL | |
http://www.hi-ho.ne.jp/babaq/basp21.html | |
「Down Load! BASP21-2003-0211.exe (1.44MB)」をクリック | |
■参照設定 | |
Basp21 1.0 Type Library | |
■参考 | |
BASP21ソケットオブジェクト | |
http://www.hi-ho.ne.jp/babaq/basp21s.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment