【发布时间】:2018-11-03 04:57:48
【问题描述】:
我正在尝试使用 Couchbase REST API 将文档添加到现有文档中。我只是在编写代码时在 Postman 中测试它。
POST:
http://<ip>:8091/pools/default/buckets/<bucketname>/docs/testdoc1?rev=1
Headers:
Accept: application/json
Authorization : xxxxx
Body:
Raw JSON (application/json)
{
"Name": "xxx",
"Address": "yyy",
"Phone number": "xxxx",
"Badge": "yyy",
"BadgeType": "xxx"
}
当我在 Postman 中发送上面时,它正在添加这个新文档。在 couchbase 文档/存储桶下,但在 body 字段上显示为“二进制文档,base64 不可用”
我什至从我的 html 代码中尝试过,但是在 couchbase 端没有收到 json 正文。
<!DOCTYPE html>
<html>
<body>
<input type="submit" value="Start" onclick="submit()">
<script type="text/javascript">
var params = {
"Name": "xxx",
"Address": "yyy",
"Phone number": "xxxx",
"Badge": "yyy",
"BadgeType": "xxx"
}
function submit() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
alert(xhr.response);
}
}
xhr.open('post', 'http://<ip>:8091/pools/default/buckets/<buckname>/docs/testdochtml?rev=1', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('Authorization', 'Basic ' + 'xxxxxxx');
xhr.send(JSON.stringify(params));
}
</script>
<p>Click on the submit button.</p>
</body>
</html>
有人可以指导我为什么 JSON 不能以正确的方式进入 couchbase 吗?
【问题讨论】: