我正在尝试通过 http (SOAP) 连接到服务器。
但我收到一个错误:401 - Unauthorized: Access is denied due to invalid credentials
.
那么,如何在请求之前发送凭据?到目前为止,我已经到了这里。
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))
}
谢谢。