NTLM Authentication in Go HTTP Requests with System Credentials
In this question, the user seeks guidance on performing Windows NTML authentication in a Go HTTP request using the system credentials of the calling user. They provide examples from C# and Python that demonstrate how to achieve this in those languages.
The solution lies in utilizing the go-ole library, which enables the use of WinHTTPRequest in Go. By following a similar approach as the Python example, it is possible to implement NTML authentication with system credentials in Go.
Here is the provided code snippet in Go that accomplishes this:
<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() unknown, _ := oleutil.CreateObject("WinHTTP.WinHTTPRequest.5.1") request, _ := unknown.QueryInterface(ole.IID_IDispatch) oleutil.CallMethod(request, "SetAutoLogonPolicy", 0) oleutil.CallMethod(request, "Open", "GET", "http://example.com", false) oleutil.CallMethod(request, "Send") resp := oleutil.MustGetProperty(request, "ResponseText") fmt.Println(resp.ToString()) }</code>
This code initializes the WinHTTPRequest object, sets the auto logon policy to use the current user's credentials, opens a GET request to the specified URL, sends the request, and retrieves the response text.
The above is the detailed content of How to Perform NTLM Authentication in Go HTTP Requests with System Credentials?. For more information, please follow other related articles on the PHP Chinese website!