2016-07-07 1 views

답변

1

MSXML 라이브러리는 VBA 내에 사용할 수 있습니다. 그런 다음 XMlHTTP 요청을 만들고 GET 또는 POST 등을 수행 할 수 있습니다. 아래 코드 샘플이 있습니다. 늦은 즉 먼저 라이브러리를 참조 할 필요 바인딩을 사용 :이 테스트 웹 사이트를 사용하고

Option Explicit 

Sub Test_LateBinding() 

    Dim objRequest As Object 
    Dim strUrl As String 
    Dim blnAsync As Boolean 
    Dim strResponse As String 

    Set objRequest = CreateObject("MSXML2.XMLHTTP") 
    strUrl = "https://jsonplaceholder.typicode.com/posts/1" 
    blnAsync = True 

    With objRequest 
     .Open "GET", strUrl, blnAsync 
     .SetRequestHeader "Content-Type", "application/json" 
     .Send 
     'spin wheels whilst waiting for response 
     While objRequest.readyState <> 4 
      DoEvents 
     Wend 
     strResponse = .ResponseText 
    End With 

    Debug.Print strResponse 

End Sub 

-JSONPlaceholder을 - 편안한 API를 호출 할 수 있습니다. 당신이) 동기 요청을 할 경우, 나는이 방법이 웹 사이트에 대한 호출이 발견

enter image description here

주 실패, 또는 ​​b) http하지 https를 사용 :이 반응이다.

+0

감사합니다. Robin 오늘 시험해 보겠습니다. – AndroidMechanic

+0

감사합니다. 작동합니다. – AndroidMechanic