在所有示例中,documentation here都显示了它们使用curl进行身份验证。还有针对各种语言的some examples here。但是,我正在尝试将API与polymer的iron-ajax元素一起使用,但在进行身份验证时遇到了问题。
我尝试基于他们的nodejs示例并将其包含在params中,但它仍然不起作用。
<template is="dom-bind" id="app">
<iron-ajax auto
url="https://<mydomain>.freshdesk.com/api/v2/tickets"
params='{ "user": "<myapitoken>", "pass": "X", "sendImmediately": "true" }'
handle-as="json"
last-response="{{ajaxResponse}}"></iron-ajax>
<template is="dom-repeat" items="[[ajaxResponse.items]]">
<mhc-ticket ticket-id="[[item.id]]"></mhc-ticket>
</template>
</template>我只是得到了一个401 (Unauthorized)。我该如何进行身份验证?
发布于 2016-06-14 23:55:58
我必须将参数移动到标头,将with-credentials设置为true,并强制method为"GET“。它现在起作用了:
<template is="dom-bind" id="app">
<iron-ajax auto
url="https://<mydomain>.freshdesk.com/api/v2/tickets"
headers='{ "user": "<myapikey>", "pass": "X", "sendImmediately": "true" }'
handle-as="json"
method="GET"
last-response="{{ajaxResponse}}"
with-credentials></iron-ajax>
<template is="dom-repeat" items="[[ajaxResponse.items]]">
<mhc-ticket ticket-id="[[item.id]]"></mhc-ticket>
</template>
</template>https://stackoverflow.com/questions/37816344
复制相似问题