2013-06-24 56 views
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)) 
} 

谢谢。

回答

相关问题