【发布时间】: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 使用相同的令牌时,它工作正常。