Created
March 13, 2015 13:00
-
-
Save uolter/1df07712954428ed6397 to your computer and use it in GitHub Desktop.
Dump http post with json
This file contains hidden or 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 ( | |
"encoding/json" | |
"io/ioutil" | |
"log" | |
"net/http" | |
) | |
type test_struct struct { | |
Test string | |
} | |
func parse_json(rw http.ResponseWriter, req *http.Request) { | |
body, err := ioutil.ReadAll(req.Body) | |
if err == nil { | |
log.Println("---> Body") | |
log.Println(string(body)) | |
} else { | |
log.Println(err) | |
} | |
req.ParseForm() | |
log.Println(req.Form) | |
var t test_struct | |
for key, _ := range req.Form { | |
log.Println(key) | |
//LOG: {"test": "that"} | |
err := json.Unmarshal([]byte(key), &t) | |
if err != nil { | |
log.Println(err.Error()) | |
} | |
} | |
//LOG: that | |
log.Println(t.Test) | |
} | |
func main() { | |
http.HandleFunc("/create_project", parse_json) | |
log.Fatal(http.ListenAndServe(":9999", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment