クラシックASPで簡単なWeb APIを叩いてみる

BASP21で無理やりやってみましたw ふつーはASP.NETに移行するよねww
#まぁ、お仕事ですから > クラシックASP

'
'	BASP21のw3getメソッドを使って指定されたURLのデータを取得して返す
'
function GetUrlData(url)
	Dim cFso, cFile
	Set cFso = Server.CreateObject("Scripting.FileSystemObject")

	Dim sDir, sPath
	sDir = Server.MapPath(Request.ServerVariables("URL"))
	sDir = Left(sDir, InStrRev(sDir, "\")) & "Downloads"
	If Not cFso.FolderExists(sDir) Then cFso.CreateFolder(sDir)
	sPath = sDir & "\" & cFso.GetTempName

	Dim w3getOptions, path
	w3getOptions = "-p 192.168.1.100:8080" 'Your HTTP-Proxy Server HERE

	Dim basp21
	Set basp21 = Server.CreateObject("basp21")
	basp21.W3get(w3getOptions & " -o " & sPath & " " & url)

	Const ForReading = 1
	Set cFile = cFso.OpenTextFile(sPath, ForReading)

	Dim value
	value = cFile.ReadAll()
	cFile.Close()
	cFso.DeleteFile(sPath)	

	Set cFile = Nothing
	Set cFso = Nothing

	GetUrlData = value
end function

Response.Write GetUrlData("http://www.some-site.com/api/some-service.cgi?p=12345678")

その後、上司にMSXML2.XMLHTTPを使えばいいんじゃない?と指摘されました。
もう、実装しちゃった後でしたが確かにそうです・・・orz
MSXML2.XMLHTTPの参考ページは例えばWeb ページをダウンロードする方法〜 MSXML 編〜とかです。

#作り直すのが面倒&納期が迫っているのでこのまま行きます。(^^;