[英]POST an Issue to Github using iron-ajax
即使我发现了一些与我的问题相似的文章,也没有答案解决了我的问题:
我希望每个(匿名)用户都可以将问题发布到Github。 当我已经使用Polymer和Webcomponents进行开发时,我想使用<iron-ajax>
来做到这一点,所以我有了<iron-ajax>
元素:
<iron-ajax
id="githubIssues"
url="https://api.github.com/repos/IchordeDionysos/social-contacts/issues"
method="POST"
params='{"access_token": "efd925cc3c8d593b720f0d6a88f3c36f593e063a"}'
body="[[params]]"
verbose
handle-as="json"
on-response="showSuccess">
</iron-ajax>
我定义了params属性,如下所示:
params: {
notify: true,
type: Object,
value: {
"title": "",
"body": "",
"assignee": "IchordeDionysos",
"labels": ["0 - Backlog"]
}
}
最后,我有一个按钮,该按钮调用该函数来发布问题,在该函数中,我检查服务器<paper-checkboxes>
是否已选中以及是否将其他标签压入参数:
submitIssue: function() {
if (this.$.bug.checked) {
this.push('params.labels', 'bug');
};
if (this.$.help.checked) {
this.push('params.labels', 'help');
};
if (this.$.question.checked) {
this.push('params.labels', 'question');
};
if (this.$.feature.checked) {
this.push('params.labels', 'feature');
};
if (this.$.enhancement.checked) {
this.push('params.labels', 'enhancement');
};
if (this.$.design.checked) {
this.push('params.labels', 'design');
};
console.log(this.params);
this.$.githubIssues.generateRequest();
}
但是,当我尝试发布问题时,我得到了400 (Bad Request)
如何解决此问题以及必须授予令牌的范围?
编辑:这是我的请求标头和正文的样子: http : //requestb.in/11y0i0x1?inspect
编辑:[对象对象]发送到正文看起来像这样:
{title: "dsggsdf",
body: "sdfgsdfsdf",
assignee: "IchordeDionysos",
labels: Array[3]}
和标签Array:
labels: Array[3]
0: "0 - Backlog"
1: "help"
2: "question"
当我将对象记录到Chrome控制台时
只需将属性content-type="application/json"
到您的iron-ajax属性中即可!
没有content-type
type-属性,ajax会将body
提供的数据作为String发送,而不是作为json对象发送,因为您必须将其发布到Github!
您必须添加属性contentType="application/json"
像这样:
<iron-ajax
id="githubIssues"
url="https://api.github.com/repos/IchordeDionysos/social-contacts/issues"
method="POST"
params='{"access_token": "efd925cc3c8d593b720f0d6a88f3c36f593e063a"}'
body="[[params]]"
verbose
handle-as="json"
on-response="showSuccess"
contentType="application/json">
</iron-ajax>
我希望这有效;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.