>  기사  >  백엔드 개발  >  Windows 시스템 자격 증명을 사용하여 Go HTTP NTLM 요청을 인증하는 방법은 무엇입니까?

Windows 시스템 자격 증명을 사용하여 Go HTTP NTLM 요청을 인증하는 방법은 무엇입니까?

Barbara Streisand
Barbara Streisand원래의
2024-10-24 19:11:02117검색

How to Authenticate Go HTTP NTLM Requests with Windows System Credentials?

Go HTTP NTLM 요청의 Windows 시스템 자격 증명: Go-OLE를 사용한 솔루션

Go HTTP 요청에서 NTLM 인증을 수행하려면 Windows 사용자의 시스템 자격 증명을 사용하려면 다음 접근 방식을 고려하세요.

Go의 COM 상호 운용성 지원을 활용하면 WinHTTPRequest 개체를 활용하여 NTLM 인증으로 HTTP 연결을 설정할 수 있습니다. go-ole 패키지를 활용하면 다음과 같이 달성할 수 있습니다.

<code class="go">package main

import (
    "fmt"

    ole "github.com/go-ole/go-ole"
    "github.com/go-ole/go-ole/oleutil"
)

func main() {
    ole.CoInitialize(0)
    defer ole.CoUninitialize()

    // Create a WinHTTPRequest object
    unknown, _ := oleutil.CreateObject("WinHTTP.WinHTTPRequest.5.1")
    request, _ := unknown.QueryInterface(ole.IID_IDispatch)

    // Set the auto login policy to use system credentials
    oleutil.CallMethod(request, "SetAutoLogonPolicy", 0)

    // Open the request with the desired URL
    oleutil.CallMethod(request, "Open", "GET", "http://example.com", false)

    // Send the request
    oleutil.CallMethod(request, "Send")

    // Retrieve the response text
    resp := oleutil.MustGetProperty(request, "ResponseText")

    // Print the response
    fmt.Println(resp.ToString())
}</code>

go-ole 패키지를 활용하여 WinHTTPRequest 개체와 상호 작용함으로써 이 코드 조각은 다음을 사용하여 NTLM 인증을 수행하는 솔루션을 제공합니다. 사용자 이름이나 비밀번호를 수동으로 지정할 필요 없이 Windows 사용자의 시스템 자격 증명.

위 내용은 Windows 시스템 자격 증명을 사용하여 Go HTTP NTLM 요청을 인증하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.