rest api使用总是报出404错误
使用localhost:99/api/v1/ping 网页能够返回pong字符串; 使用localhost:99/api/v1/stl/channels?siteId=436 就报出404页面错误, 使用localhost:99/api/v1/contents/436/438 HTTP/1.1?X-SS-API-KEY=5efbca9d-170d-4973-80db-2******1ba4 也是报出404错误 想问下大神这个rest api到底是怎样使用的?
你可以这样试试 我的是拿到数据了
X-SS-API-KEY是要添加的一个请求头 里面放token也就是API秘钥
代码:
$.ajax({
type:"GET",
url:'/api/v1/stl/channel?siteId=1',
beforeSend: function(xhr){xhr.setRequestHeader('X-SS-API-KEY', 'API秘钥放到这里就行了');},//这里设置header
success: function() {
console.log('添加成功!')
},
error:function(){
console.log('请求失败!')
}
})
使用localhost:99/api/v1/ping 网页能够返回pong字符串; 使用localhost:99/api/v1/stl/channels?siteId=436 就报出404页面错误, 使用localhost:99/api/v1/contents/436/438 HTTP/1.1?X-SS-API-KEY=5efbca9d-170d-4973-80db-2******1ba4 也是报出404错误 想问下大神这个rest api到底是怎样使用的?
请问你有搞明白这个用restapi添加内容嘛?我最近也发现了没有办法添加,可以查询出来,就是不能添加内容,会报这个错误
如果你有搞明白怎么添加了,麻烦告知一下,多谢
获取内容搞明白了,修改内容没弄明白,你有没有在管理后台勾选contents授予api秘钥权限;
官方demo是这样:
POST /api/v1/contents/1325/1344 HTTP/1.1
Content-Type: application/json
X-SS-API-KEY: 7cd22002-27a7-4c5d-ba4d-a1c108a20eaf
{
"title": "标题",
"content": "内容正文"
}
我使用ajax是这样:
$.ajax({
type: "put",
url: "/api/v1/contents/449/"+channelid+"/"+contentid,
data: {
"Content-Type": "application/json",
"apikey": "abe********82c",
"title": "标题",
"content": "内容正文"
},
success: function (res) {
}
发送请求获取数据失败,请问有谁知道吗?
使用了beforeSend: function(xhr){xhr.setRequestHeader('X-SS-API-KEY', 'API秘钥放到这里就行了');},好像还是不可以,我自己用的是这种 `$.ajax({ type: "GET", url: 'http://xxxx/api/v1/contents/' + siteId + '/' + channelId + '?apiKey=' + apikey + ' HTTP/1.1', contentType: "application/json", cache: false, error: function (data) { console.log(xmlobj) }, success: function(data){ console.log(data) },
});`
这个用来调内容API是可以的,但是我用这种方法去调users的API时,就出现了【Access to XMLHttpRequest at 'http://xxxx/api/v1/users%20HTTP/1.1' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.】这种错误,哪位大神帮忙解答一下