Skip to content

Instantly share code, notes, and snippets.

@wjiec
Last active November 5, 2019 15:54
Show Gist options
  • Save wjiec/4f76bb61e29d327fead958cde0f6f1b0 to your computer and use it in GitHub Desktop.
Save wjiec/4f76bb61e29d327fead958cde0f6f1b0 to your computer and use it in GitHub Desktop.
微信直接打开默认浏览器
package main
import (
"log"
"net/http"
"strings"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, request *http.Request) {
userAgent := request.Header.Get("user-agent")
if strings.Contains(userAgent, "MicroMessenger") && strings.Contains(userAgent, "Android") {
w.Header().Add("Content-Disposition", "attachment; filename=1.apk")
w.Header().Add("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusPartialContent)
return
}
_, _ = w.Write([]byte("hello"))
})
log.Fatal(http.ListenAndServe(":8898", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment