diff --git a/.example/net/gtcp/gtcp_conn.go b/.example/net/gtcp/gtcp_conn.go index a312c4ead..323595751 100644 --- a/.example/net/gtcp/gtcp_conn.go +++ b/.example/net/gtcp/gtcp_conn.go @@ -16,7 +16,7 @@ func main() { } defer conn.Close() - if err := conn.Send([]byte("GET / HTTP/1.1\n\n")); err != nil { + if err := conn.Send([]byte("GET / HTTP/1.1\r\n\r\n")); err != nil { panic(err) } @@ -30,13 +30,14 @@ func main() { array := bytes.Split(data, []byte(": ")) // 获得页面内容长度 if contentLength == 0 && len(array) == 2 && bytes.EqualFold([]byte("Content-Length"), array[0]) { - contentLength = gconv.Int(array[1]) + // http 以\r\n换行,需要把\r也去掉 + contentLength = gconv.Int(string(array[1][:len(array[1])-1])) } header = append(header, data...) header = append(header, '\n') } - // header读取完毕,读取文本内容 - if contentLength > 0 && len(data) == 0 { + // header读取完毕,读取文本内容, 1为\r + if contentLength > 0 && len(data) == 1 { content, _ = conn.Recv(contentLength) break }