golang,ajax发布数据

时间:2016-09-30 04:10:55

标签: go axios

我如何在golang中获取数据ajax帖子。 我返回2个params后退令牌:'123',密码:'abc' 目前我使用ajax与aixos npm。

使用POSTMAN进行测试时,它工作正常Content-Type ='application / x-www-form-urlencoded'

行动方法:

w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Access-Control-Allow-Credentials", "true")
w.Header().Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")



    r.ParseForm()
    log.Println("Form", r.Form.Get("token"), r.Form.Get("password"), r.Form.Get("questions"))
    log.Println("PostFormValue", r.PostFormValue("token"), r.PostFormValue("params"), r.PostFormValue("password"), r.PostFormValue("questions"))
    log.Println("FormValue", r.FormValue("ajax_post_data"), r.FormValue("token"), r.FormValue("params"), r.FormValue("password"), r.FormValue("questions"))
    log.Println("r.URL.RawQuery", r.URL.RawQuery)

全部返回空字符串

这是请求:

Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:404
Content-Type:application/x-www-form-urlencoded
Host:localhost:5500
Origin:http://localhost:8080
Pragma:no-cache
Referer:http://localhost:8080/perform-survey/step1?token=abc123
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.108 Safari/537.36

0 个答案:

没有答案