【问题标题】:Rest API Authentication with Autohotkey使用 Autohotkey 进行 Rest API 身份验证
【发布时间】:2018-04-17 06:05:36
【问题描述】:

我想将带有 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

所以这是我的问题:我将身份验证信息放在哪里? 我读到,我已经将字符串 username:password 编码为 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"}}}

怎么了?

【问题讨论】:

标签: rest api autohotkey


【解决方案1】:

您可以使用 base64 编码格式发送用户名/密码,如下所示:

HttpObj.setRequestHeader('Authorization', 'Basic [base64 encoded password here]' );

【讨论】:

  • 非常感谢!现在没有像 "Authentication failed, but {"statusCode":500,"message":"org.codehaus.jackson.JsonParseException: Unexpected character (':' (code 58)): was Expecting comma to separate ARRAY entries \n 在 [来源:com.atlassian.confluence.plugins.restapi.filters.LimitingRequestFilter$1@5b2da977;行:1,列:73]"}
  • @Folllast .. ':' 冒号是 json 键值分隔符,因为它是 JSON 请求的一部分,所以它会抛出错误。您是否引用了您的用户名:密码编码字符串。您能显示您发送的身份验证内容吗?您可以放置​​用户名/密码的虚拟值。
猜你喜欢
  • 1970-01-01
  • 2013-01-05
  • 2018-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-11
相关资源
最近更新 更多