我有一个用Angular 4编写的应用程序调用本地主机但不同端口上的couchdb。角4呼叫couchdb有CORS错误,但没有预检显示在提琴手
我一直在使用couchdb与Aurelia应用程序没有任何问题。
现在我正在切换到Angular 4和Angular MD,我似乎可以通过这个cors问题。
这里是调用的CouchDB
私人commonUpdate代码(含量:任何,网址:串,方法:串= '把'){
console.log("in common") const myHeaders = new Headers(); myHeaders.append('Content-Type', 'application/json'); const options = new RequestOptions({ headers: myHeaders, withCredentials: true }); if (content && content._rev && content._rev.length >= 5) { url = url + '/' + content._id; } const status = new DbStatus(); status.ok = false; let response: any; try { if (content) { const contentJson: string = JSON.stringify(content); this.http.post(url, contentJson, options).map(res => res.json()).subscribe(data => { console.log(data['results']); }) } status.ok = this.isHttpStatusSuccess(response.status); if (status.doc) { if (Array.isArray(status.doc.docs)) { if (status.doc.docs.length === 0) { status.ok = false; status.reason = 'Empty Array'; if (!status.error) status.error = status.reason; } } } status.httpStatus = response.status; status.response = response; } catch (error) { status.ok = false; }
错误消息:
VM27427:1 XMLHttpRequest无法加载localhost:5984/_session。协议方案仅支持跨源请求:http,data,chrome,chrome-extension,https。
[cors]
origins = *
credentials = true
headers = accept, authorization, content-type, origin, referer
Couch-Rev, Set-Cookie
methods = GET, PUT, POST, HEAD, DELETE
我不明白为什么这个工作。 再次fiddler不显示预检OPTION方法请求。
但是,从邮递员运行OPTION方法返回允许GET和HEAD的方法。也许浏览器缓存它,但我的开发工具打开缓存禁用设置选中。
建议