문제

Visual Basic 스크립트 내에서 HTTP GET 요청을 수행하는 방법이 있습니까? 처리를 위해 특정 URL에서 응답의 내용을 가져와야합니다.

도움이 되었습니까?

해결책

Dim o
Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "http://www.example.com", False
o.send
' o.responseText now holds the response as a string.

다른 팁

글을 쓰는 시점에서 응답으로 무엇을 할 것인지 또는 콘텐츠 유형이 무엇인지 설명하지 않았습니다. 답은 이미 매우 기본적인 사용법을 포함하고 있습니다 MSXML2.XMLHTTP (더 명시적인 것을 추천합니다 MSXML2.XMLHTTP.3.0 progid) 그러나 응답으로 다른 일을해야 할 수도 있지만 텍스트가 아닐 수도 있습니다.

xmlhttp도 a responseBody 바이트 배열 버전 인 Reponse의 속성은 다음과 같습니다. responseStream 그것은 IStream 응답을위한 래퍼.

서버 측 요구 사항 (예 : ASP에서 호스팅 된 vbscript)에서 MSXML.ServerXMLHTTP.3.0 또는 WinHttp.WinHttpRequest.5.1 (거의 동일한 인터페이스가 있습니다).

다음은 XMLHTTP를 사용하여 PDF 파일을 가져와 저장하는 예입니다.

Dim oXMLHTTP
Dim oStream

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")

oXMLHTTP.Open "GET", "http://someserver/folder/file.pdf", False
oXMLHTTP.Send

If oXMLHTTP.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write oXMLHTTP.responseBody
    oStream.SaveToFile "c:\somefolder\file.pdf"
    oStream.Close
End If

GET 요청을 사용하여 실제로 데이터를 전송하는 경우 ...

확인하다:http://techhelplist.com/index.php/tech-tutorials/37-windows-troubles/60-vbscript-sending-get-request

msxml2.xmlhttp의 문제점은 Windows OS 버전 및 패치에 따라 다른 이름을 가진 여러 버전이 있다는 것입니다.

이것은 다음과 같이 설명합니다.http://support.microsoft.com/kb/269238

vbscript를 사용하여 전화를 걸어 운이 더 많았습니다

set ID = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "http://example.com/parser.php?key=" & value & "key2=" & value2 
do while IE.Busy.... 

.... 그리고 더 많은 것들이 있지만 요청을 겪게하기 위해.

        strRequest = "<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" " &_
         "xmlns:tem=""http://tempuri.org/"">" &_
         "<soap:Header/>" &_
         "<soap:Body>" &_
            "<tem:Authorization>" &_
                "<tem:strCC>"&1234123412341234&"</tem:strCC>" &_
                "<tem:strEXPMNTH>"&11&"</tem:strEXPMNTH>" &_
                "<tem:CVV2>"&123&"</tem:CVV2>" &_
                "<tem:strYR>"&23&"</tem:strYR>" &_
                "<tem:dblAmount>"&1235&"</tem:dblAmount>" &_
            "</tem:Authorization>" &_
        "</soap:Body>" &_
        "</soap:Envelope>"

        EndPointLink = "http://www.trainingrite.net/trainingrite_epaysystem" &_
                "/trainingrite_epaysystem/tr_epaysys.asmx"



dim http
set http=createObject("Microsoft.XMLHTTP")
http.open "POST",EndPointLink,false
http.setRequestHeader "Content-Type","text/xml"

msgbox "REQUEST : " & strRequest
http.send strRequest

If http.Status = 200 Then
'msgbox "RESPONSE : " & http.responseXML.xml
msgbox "RESPONSE : " & http.responseText
responseText=http.responseText
else
msgbox "ERRCODE : " & http.status
End If

Call ParseTag(responseText,"AuthorizationResult")

Call CreateXMLEvidence(responseText,strRequest)

'Function to fetch the required message from a TAG
Function ParseTag(ResponseXML,SearchTag)

 ResponseMessage=split(split(split(ResponseXML,SearchTag)(1),"</")(0),">")(1)
 Msgbox ResponseMessage

End Function

'Function to create XML test evidence files
Function CreateXMLEvidence(ResponseXML,strRequest)

 Set fso=createobject("Scripting.FileSystemObject")
 Set qfile=fso.CreateTextFile("C:\Users\RajkumarJoshua\Desktop\DCIM\SampleResponse.xml",2)
 Set qfile1=fso.CreateTextFile("C:\Users\RajkumarJoshua\Desktop\DCIM\SampleReuest.xml",2)

 qfile.write ResponseXML
 qfile.close

 qfile1.write strRequest
 qfile1.close

End Function
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top