cscript 發http請求

run.bat 

c:\windows\syswow64\cscript.exe http.vbs
pause

http.vbs 

Function SaveHtml(p_name, p_body)
	On Error Resume Next
	Dim ado
	Set ado = CreateObject("ADODB.Stream")
	ado.Mode = adModeReadWrite
	ado.Type = adTypeBinary
	ado.Open
	ado.Write p_body
	ado.SaveToFile p_name, adSaveCreateOverWrite
End Function

Public Function URLEncode(strURL)
	Dim msc
	Set msc = CreateObject("MSScriptControl.ScriptControl")
	msc.AllowUI = False
	msc.Language = "JSCRIPT"
	msc.AddCode "test=encodeURIComponent(""" & strURL & """);"
	URLEncode = msc.Eval("test")
End Function

Function SaveTxt(p_name, p_contents)
	dim fso, f
	set fso = CreateObject("Scripting.FileSystemObject")
	set f = fso.CreateTextFile(p_name, true) '第二個參數表示目標文件存在時是否覆蓋
	'f.Write("寫入內容")
	f.WriteLine(p_contents) '寫入內容並換行
	'f.WriteBlankLines(3) '寫入三個空白行(相當於在文本編輯器中按三次回車)
	f.Close()
End Function

Function http(url)
		On Error Resume Next '隨後的程序即便出現"運行時錯誤"時,也不會顯示"出錯信息",並且會繼續運行下去.
	Dim winhttp
	Set winhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
	winhttp.open "GET", url, False
	'winhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	'winhttp.Option(6) = 0
	winhttp.Send
	winhttp.WaitForResponse
	
	'WSH.Echo Time& url
	'WSH.Echo Time& winhttp.ResponseText
	 http=Time& url '函數返回值
End Function


WSH.Echo Date&" "& Time&" 程序開始"

Do While True
	WSH.Echo http("http://wjsou.com")
	If True Then
		Exit Do
	'Else
		'WSH.Echo Time&" else"
	End If
Loop

WSH.Echo Date&" "& Time&" 程序結束"


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章