1 回答
TA贡献1804条经验 获得超2个赞
我很高兴与您分享我达到了所需的实现。
下面的代码有效!
感谢您的评论指导我找到正确的方法来完成这项任务:
package main
import (
"bufio"
"crypto/tls"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
)
func main() {
cmdSecSMS := "GET https://10.xxx.xx.x:xx43/httpgw.conf?" +
"Type=SMS&Address=5511111&MsgID=123&Notify=N&Validity=24:00&OAdC=15555&" +
"Message=blablah " +
"HTTP/1.1"
fmt.Println(cmdSecSMS)
cmdSecUrlSMS := cmdSecSMS
hostName := "10.xxx.xx.x"
portNum := "xx43"
doDial(cmdSecUrlSMS, hostName, portNum)
//doClientTrans(cmdSecUrlSMS)
//doGetClient(cmdSecUrlSMS)
//doGet(cmdSecUrlSMS)
}
func doDial(cmd, host, port string) {
// connect to this socket
conn, err := net.Dial("tcp", host+":"+port)
if err != nil {
fmt.Printf("Some error %v", err)
return
} else {
defer conn.Close()
fmt.Printf("Connection established between %s and localhost.\n", host)
fmt.Printf("Local Address : %s \n", conn.LocalAddr().String())
fmt.Printf("Remote Address : %s \n", conn.RemoteAddr().String())
// send to socket
fmt.Fprintf(conn, cmd+"\n")
// listen for reply
message, _ := bufio.NewReader(conn).ReadString('\n')
fmt.Print("Message from server: " + message)
}
}
谢谢小伙伴们的支持!
- 1 回答
- 0 关注
- 289 浏览
添加回答
举报