Browse Source

dumprequest can dump multipart-encoded form now.

master
Patrick Peng Sun 8 years ago
parent
commit
c8a5c8bfd9
1 changed files with 32 additions and 5 deletions
  1. +32
    -5
      main.go

+ 32
- 5
main.go View File



import ( import (
"fmt" "fmt"
"io"
"log" "log"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"os"
"strconv" "strconv"
"strings"
"time" "time"
) )


// TODO: setup GlobalPath Config, from reading file // TODO: setup GlobalPath Config, from reading file
var GlobalPath = PathsConfig{ var GlobalPath = PathsConfig{
"dist/", "dist/",
"/mnt/data/workspace/go/src/wechat_hitxy/spa/",
"spa/",
} }


//KFUsers info cache about current customer service //KFUsers info cache about current customer service
w.Header().Set("Access-Control-Expose-Headers", "Set-Cookie,myheader,*") w.Header().Set("Access-Control-Expose-Headers", "Set-Cookie,myheader,*")
w.Header().Set("myheader", "myheader-data") w.Header().Set("myheader", "myheader-data")


expiration := time.Now().Add(10 * 365 * 24 * time.Hour)
str := time.Now().String()
cookie := http.Cookie{Name: "username", Value: str, Expires: expiration}
http.SetCookie(w, &cookie)
// expiration := time.Now().Add(10 * 365 * 24 * time.Hour)
// str := time.Now().String()
// cookie := http.Cookie{Name: "username", Value: str, Expires: expiration}
// http.SetCookie(w, &cookie)


fmt.Fprintf(w, `{"status":"OK"}`) fmt.Fprintf(w, `{"status":"OK"}`)
for _, c := range r.Cookies() { for _, c := range r.Cookies() {
log.Println(c.Name) log.Println(c.Name)
log.Println(c.Value) log.Println(c.Value)
} }

err := r.ParseMultipartForm(32 << 20)
if err == nil {
for k, v := range r.Form {
fmt.Println("key:", k)
fmt.Println("val:", strings.Join(v, ""))
}

file, handler, err := r.FormFile("avatar")
if err == nil {
defer file.Close()
log.Printf("%v", handler.Header)
log.Println(handler.Filename)
f, err := os.OpenFile("/tmp/wechat_hitxy_avatar_upload.jpg", os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
io.Copy(f, file)
}
} else {
log.Print(err)
}
} }


func supplyAccessToken(w http.ResponseWriter, r *http.Request) { func supplyAccessToken(w http.ResponseWriter, r *http.Request) {

Loading…
Cancel
Save