2013-12-16 3 views
0

Excel에서 인증이 필요한 WebAPI를 사용할 수 있습니까? 일반 .Net 클라이언트의 경우 WebAPI의 Token 끝점에 인증 자격 증명을 보내고 이후 호출에서 무기명으로 첨부되는 토큰을받습니다. 그러나 Excel에서이 작업을 어떻게 수행합니까? VBA 코드에서 어떤 오브젝트를 사용해야합니까?Excel에서 안전한 ASP.Net WebAPI 사용하기

WebAPI는 Excel에서 열과 행으로 표시해야하는 개체 모음을 반환합니다.

+0

[Excel 2010 인증을 사용하여 웹 API를 사용하는 방법] (http://stackoverflow.com/q/18119393/456814)의 중복. –

답변

1

XHR을 기억하나요, 아니면 XML HTTP 요청이라고해야하나요? :)

Dim xhr As Object 

On Error Resume Next 
Set xhr = CreateObject("MSXML2.XMLHTTP") 

If Err.Number <> 0 Then 
    Set xhr = CreateObject("MSXML.XMLHTTPRequest") 
    Application.StatusBar = "Error 0, has occured while creating a MSXML.XMLHTTPRequest object" 
End If 

If xhr Is Nothing Then 
    Application.StatusBar = "For some reason it wasn't possible to make a MSXML2.XMLHTTP object" 
    Exit Function 
End If 

'consuming the web service. 
xhr.Open "POST", "/webservice/url/goes/here", False 
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
xhr.send "post parameters can be sent here format: paramname=paramvalue&paramname2=paramvalue2" 

If xhr.Status = 200 Then  
    'creating the XmlDocument to load the received data. 
    Dim xDoc As MSXML2.DOMDocument60 
    Set xDoc = CreateObject("Msxml2.DOMDocument.6.0") 
    xDoc.setProperty "ProhibitDTD", False 
    xDoc.setProperty "ResolveExternals", True 

    'loading the data into the in-memory xml document. 
    xDoc.validateOnParse = True 
    xDoc.async = False 
    xDoc.LoadXML xhr.responseText 
    Application.StatusBar = False 

    'xDoc now holds your web service returned data 
End If 

위의 코드에 연결하는 데 사용할 수 있습니다 여기에

는 Oracle 데이터베이스에서 데이터를 반환하는 웹 서비스를 호출하는 사용자를 인증하는 나는 내 프로젝트를 작성한 예입니다 웹 서비스. 이 링크 http://www.mcpher.com/Home/excelquirks/snippets/basicauth에는 기본 인증을 얻는 방법에 대한 자세한 내용이 있습니다. 이 길을 따라 당신을 도와줍니다

희망,

감사합니다.