In Go's http package, how do I get the query string on a POST request?

前端 未结 6 563
滥情空心
滥情空心 2021-01-30 03:59

I\'m using the httppackage from Go to deal with POST request. How can I access and parse the content of the query string from the Requestobject ? I can

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 04:23

    Below words come from the official document.

    Form contains the parsed form data, including both the URL field's query parameters and the POST or PUT form data. This field is only available after ParseForm is called.

    So, sample codes as below would work.

    func parseRequest(req *http.Request) error {
        var err error
    
        if err = req.ParseForm(); err != nil {
            log.Error("Error parsing form: %s", err)
            return err
        }
    
        _ = req.Form.Get("xxx")
    
        return nil
    }
    

提交回复
热议问题