我想将带有Autohotkey的字符串发布到Rest API。
在另一个问题上,我发现了这样的事情:
URL := "http://localhost:8000/createPlayer"
HttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HttpObj.Open("POST", URL, 0)
HttpObj.SetRequestHeader("Content-Type", "application/json")
json_str := ({"name": "Any Name"})
Body = json_str
HttpObj.Send(Body)
MsgBox, %Body%
Result := HttpObj.ResponseText
Status := HttpObj.Status
msgbox % "status: " status "`n`nresult: " result
所以这是我的问题:我在哪里放置身份验证信息? 我读过,我已经把字符串用户名:密码编码为Base64到API,但在哪里?非常感谢你。
文档中的示例是(有curl):
curl -u admin:admin -X POST -H 'Content-Type: application/json'
-d'{"type":"page","title":"new page",
"ancestors":[{"id":456}], "space":{"key":"TST"},"body":{"storage":
{"value":
"<p>This is a new page</p>","representation":"storage"}}}'
http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
我的json_string是:
{"type":"page","title":"new page","ancestors":[{"id":13533694}, "space":{"key":"SPIELWIESE"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}
出了什么问题?
答案 0 :(得分:1)
您可以使用base64编码格式发送用户名/密码,如下所示:
HttpObj.setRequestHeader('Authorization', 'Basic [base64 encoded password here]' );