📌  相关文章
📜  如何在 golang 中发送应用程序 x-www-form-urlencoded 请求 - Go 编程语言 - Go 编程语言代码示例

📅  最后修改于: 2022-03-11 14:45:01.802000             🧑  作者: Mango

代码示例1
// Adding key:values into application/x-www-form-urlencoded type req
form := url.Values{}
form.Add("key1", "value1")
form.Add("key2", "value2")
form.Add("key3", "value3")

// Preparing HTTP Request
req, err := http.NewRequest("POST", HOST, strings.NewReader(form.Encode()))
if err != nil {
    e.Logger.Info("Error: %v", err)
    return err
}

// Setting Content Type
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

// Sending HTTP request
respNew, err := http.DefaultClient.Do(req)
if err != nil {
      e.Logger.Info("Error: %v", err)
    return err
}