Created
November 17, 2013 17:15
-
-
Save dylanmei/7515652 to your computer and use it in GitHub Desktop.
WinRM's equivalent of Hello World in Go, from the XML sample in on the front page of MSDN's WS-Management documentation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/base64" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
) | |
var user = "vagrant" | |
var pass = "vagrant" | |
func main() { | |
command := `<s:Envelope | |
xmlns:s="http://www.w3.org/2003/05/soap-envelope" | |
xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" | |
xmlns:w="http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd" | |
> | |
<s:Header> | |
<a:To>http://RemoteComputer:80/wsman</a:To> | |
<w:ResourceURI s:mustUnderstand="true"> | |
http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_logicaldisk | |
</w:ResourceURI> | |
<a:ReplyTo> | |
<a:Address s:mustUnderstand="true"> | |
http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous | |
</a:Address> | |
</a:ReplyTo> | |
<a:Action s:mustUnderstand="true"> | |
http://schemas.xmlsoap.org/ws/2004/09/transfer/Get | |
</a:Action> | |
<w:MaxEnvelopeSize s:mustUnderstand="true">153600</w:MaxEnvelopeSize> | |
<a:MessageID>uuid:4ED2993C-4339-4E99-81FC-C2FD3812781A</a:MessageID> | |
<w:Locale xml:lang="en-US" s:mustUnderstand="false"/> | |
<w:SelectorSet> | |
<w:Selector Name="DeviceId">c:</w:Selector> | |
</w:SelectorSet> | |
<w:OperationTimeout>PT60.000S</w:OperationTimeout> | |
</s:Header> | |
<s:Body /> | |
</s:Envelope>` | |
request, _ := http.NewRequest("POST", | |
"http://localhost:5985/wsman", bytes.NewBufferString(command)) | |
request.Header.Add("Content-Type", "application/soap+xml;charset=UTF-8") | |
request.Header.Add("Authorization", "Basic "+ | |
base64.StdEncoding.EncodeToString([]byte(user+":"+pass))) | |
client := &http.Client{} | |
response, err := client.Do(request) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("HTTP Status", response.Status) | |
for key, value := range response.Header { | |
fmt.Println(" ", key, ":", value) | |
} | |
defer response.Body.Close() | |
body, _ := ioutil.ReadAll(response.Body) | |
fmt.Printf("%s", body) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should print something like...