3
我試圖通過http(SOAP)連接到服務器。如何通過Go進行身份驗證並通過http發送xml(golang)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))
}
謝謝。