Created
May 13, 2014 05:32
-
-
Save lintianzhi/1b99f45ea82628ad55ed to your computer and use it in GitHub Desktop.
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 ( | |
"fmt" | |
"net" | |
) | |
func main() { | |
ln, err := net.Listen("tcp", ":8080") | |
if err != nil { | |
// handle error | |
} | |
for { | |
conn, err := ln.Accept() | |
if err != nil { | |
// handle error | |
continue | |
} | |
fmt.Println("Accept") | |
go handleConnection(conn) | |
} | |
} | |
func handleConnection(c net.Conn) { | |
c.Write([]byte("HTTP/1.1 302 Found\r\n")) | |
c.Write([]byte("Connection: Close\r\n")) | |
c.Write([]byte("Pragma: no-cache\r\n")) | |
c.Write([]byte("Location: http://www.buxuxiao.net/wp-content/uploads/2014/05/537032598c7e7257.jpgcover.jpg?mixbttmwjzydqnay\r\n")) | |
c.Write([]byte("Content-Type: text/html; charset=UTF-8;\r\n")) | |
c.Write([]byte("Content-Length: 0;\r\n\r\n")) | |
c.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment