I am trying to authenticate myself via a Go client. Here is what i have done so far
func main() {
servAddr := "192.168.7.13:443"
tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
if err != nil {
fmt.Println("ResolveTCPAddr failed:", err.Error())
os.Exit(1)
}
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
fmt.Println("Dial failed:", err.Error())
os.Exit(1)
}
_, err = conn.Write([]byte(postReq))
if err != nil {
fmt.Println("Write to server failed:", err.Error())
os.Exit(1)
}
fmt.Println(postReq)
reply := make([]byte, 1024)
_, err = conn.Read(reply)
if err != nil {
fmt.Println("Write to server failed:", err.Error())
os.Exit(1)
}
fmt.Println("reply from server=", string(reply))
conn.Close()
}
This is the message which i am writing to the connection:
POST /ManagementServer/ServerCommandService.svc HTTP/1.1 Host: 192.xxx.xx.xx Content-Type: text/xml; charset=utf-8 Authorization: Basic {username:password in base64} Content-Length: 405 SOAPAction:"http://videoos.net/2/XProtectCSServerCommand/IServerCommandService/Login" Connection: Keep-Alive 190fc316-6412-41c4-8a9c-d468cc7bee9d
After this, I am expecting to get an authentication token, but instead i am getting a
> Write to server failed: read tcp server-ip:port->server-ip:443:
> read: connection reset by peer
What am I doing wrong? FYI, I am using the same message in python and with sockets I am able to get the token. Can someone help me do the same in Go lang? Thanks