예제 #1
0
파일: http.go 프로젝트: RezaDKhan/terraform
func Http_post(client *Client, request *soap.SoapMessage) (response string, err error) {
	httpClient := &http.Client{Transport: client.transport}

	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 프로젝트: rnaveiras/packer
func defaultHeaders(message *soap.SoapMessage, url string, params *Parameters) *soap.SoapHeader {
	return message.
		Header().
		To(url).
		ReplyTo("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous").
		MaxEnvelopeSize(params.EnvelopeSize).
		Id(genUUID()).
		Locale(params.Locale).
		Timeout(params.Timeout)
}
예제 #3
0
파일: http.go 프로젝트: rnaveiras/packer
// PostRequest make post to the winrm soap service
func PostRequest(client *Client, request *soap.SoapMessage) (string, error) {
	httpClient := &http.Client{Transport: client.transport}

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

	body, err := body(resp)
	if err != nil {
		return "", fmt.Errorf("http response error: %d - %s", resp.StatusCode, err.Error())
	}
	if resp.StatusCode != 200 {
		return "", fmt.Errorf("http error: %d - %s", resp.StatusCode, body)
	}

	return body, err
}