如何在Go(golang)SOAP中通过http进行身份验证和发送xml

I'm trying to connect to a server through http (SOAP).

But I'm getting an error: 401 - Unauthorized: Access is denied due to invalid credentials.

So, how can I send the credentials before the request? I've got here so far.

package main

import (
  "net/http"
  "bytes"
  "fmt"
  "io/ioutil"
)

func main() {

  buf := []byte(`<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ClientGetByGuid xmlns="http://tempuri.org/">
      <guid>fc40a874-2902-4539-b8e7-6aa7084644ec</guid>
    </ClientGetByGuid>
  </soap:Body>
</soap:Envelope>`)
  body := bytes.NewBuffer(buf)
  r, _ := http.Post("http://mywebsite.com.br/service.svc?wsdl", "text/xml", body)

  response, _ := ioutil.ReadAll(r.Body)
  fmt.Println(string(response))
}

Thanks.

If you are talking about HTTP Basic Auth, create a Request object and use the SetBasicAuth(username, password string) method.

See this question for more information.