Sample code for 30+ languages & platforms
Go

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat Go Downloads

Go
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http := chilkat.NewHttp()

    // To use HTTP Basic authentication:
    http.SetLogin("myLogin")
    http.SetPassword("myPassword")
    http.SetBasicAuth(true)

    // Run the test using this URL with the credentials above.  
    // (Works while httpbin.org keeps the test endpoint available.)
    jsonResponse := http.QuickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword")
    if http.LastMethodSuccess() == false {
        fmt.Println(http.LastErrorText())
        http.DisposeHttp()
        return
    }

    fmt.Println("Response status code: ", http.LastStatus())

    fmt.Println(*jsonResponse)

    // Output:

    // Response status code: 200
    // {
    //   "authenticated": true, 
    //   "user": "myLogin"
    // }

    http.DisposeHttp()