示例#1
0
文件: http.go 项目: sneal/go-winrm
func Http_post(client *Client, request *soap.SoapMessage) (response string, err error) {
	httpClient := &http.Client{}

	req, err := http.NewRequest("POST", client.url, strings.NewReader(request.String()))
	if err != nil {
		err = fmt.Errorf("impossible to create http request %s", err)
		return
	}
	req.Header.Set("Content-Type", soapXML+";charset=UTF-8")
	req.SetBasicAuth(client.username, client.password)
	resp, err := httpClient.Do(req)
	if err != nil {
		err = fmt.Errorf("unknown error %s", err)
		return
	}

	if resp.StatusCode == 200 {
		response, err = body(resp)
	} else {
		body, _ := ioutil.ReadAll(resp.Body)
		err = fmt.Errorf("http error: %d - %s", resp.StatusCode, body)
	}

	return
}
示例#2
0
文件: request.go 项目: sneal/go-winrm
func defaultHeaders(message *soap.SoapMessage, params *Parameters) (h *soap.SoapHeader) {
	h = message.Header()
	h.To(params.url).ReplyTo("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous").MaxEnvelopeSize(params.EnvelopeSize).Id(genUUID()).Locale(params.Locale).Timeout(params.Timeout)
	return
}