Skip to content

Instantly share code, notes, and snippets.

@limingzju
Created October 20, 2014 02:12
Show Gist options
  • Save limingzju/91d2bf835f37e81a8516 to your computer and use it in GitHub Desktop.
Save limingzju/91d2bf835f37e81a8516 to your computer and use it in GitHub Desktop.
http post
package main
import (
"net"
"fmt"
"io"
"bytes"
"os"
)
func post(conn net.Conn) {
b := new(bytes.Buffer)
contentLength := 300 * 1024 // 300KB
for i := 0; i < contentLength; i++ {
b.Write([]byte{'a'})
}
fmt.Fprintf(conn, "POST /sdktest-private/test-1?offset=0&complete=true&version=1.0 HTTP/1.1\r\n")
fmt.Fprintf(conn, "HOST: 223.252.196.40\r\n")
fmt.Fprintf(conn, "x-nos-token: invalid\r\n")
fmt.Fprintf(conn, "Content-Length: %d\r\n", contentLength)
fmt.Fprintf(conn, "\r\n")
io.Copy(conn, b)
}
func main() {
conn, err := net.Dial("tcp", "223.252.196.40:80")
assert(err)
for i := 0; i < 50; i++ {
post(conn)
}
io.Copy(os.Stdout, conn)
}
func assert(err error) {
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment