【问题标题】:403 forbidden error while doing POST request in GoLang在 GoLang 中执行 POST 请求时出现 403 禁止错误
【发布时间】:2018-12-27 11:41:14
【问题描述】:
//Send put request with given params
func SendPostRequest(url string, param map[string]interface{}, authToken string) string{

//to disable security check
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
//Parse to json
jsonValue, _ := json.Marshal(param)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonValue))
req.Header.Add("Content-Type", "application/json")
req.Header.Add("AuthToken", authToken)


client := &http.Client{}
resp, err := client.Do(req)
}

这是 JSON 文件

{"credentials":{"display_name":"win10Test","is_default":"","password":"","username":""},
"defaultschedule":true,"host_info":{"ip":"*.*.*.*"},
"install_agent":false,"is_auth_enabled":false,"is_enabled":true,"is_encrypted":false,
"is_synchable":false,"name":"win10","os_type":"Windows","priority":300,"use_ssl":false}

当我运行代码时,我收到以下错误 响应状态:403 禁止

【问题讨论】:

  • 请提供您使用的API的信息
  • 打印令牌并使用带有有效负载的 curl post 的令牌,令牌或有效负载可能存在问题。这将帮助您缩小问题范围
  • 查看文档以了解您使用的任何 API。这是返回 403 禁止的 API。很可能您的凭据有误。
  • 你有什么问题?
  • 我的令牌是正确的。当我对 Postman 使用相同的令牌时,它工作正常。

标签: rest go http-post


【解决方案1】:

403 是禁止请求 - https://en.wikipedia.org/wiki/HTTP_403

我认为你发送了错误的 authToken

仔细检查。

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 2014-02-20
    • 2020-09-18
    • 1970-01-01
    • 2011-03-18
    相关资源
    最近更新 更多