琥珀色的Smalltalk IDE与一个用nodejs编写的服务器一起工作。我如何配置XMLHttpRequests到同一个域的不同端口的服务器?如何允许访问不同的端口?
琥珀默认的访问是
http://127.0.0.1:4000/
,并检索和存储JSON数据我想使用CouchDB实例(默认端口为5984)
| req |
req := XMLHttpRequest new.
req open: 'GET' url: 'http://127.0.0.1:5984/' asynchronous: false.
req send: ''.
问题
由于跨域访问策略,无法访问。
注
服务器从
amber-master\bin\server.bat
称为服务器处于
amber-master\cli\js\amber-cli.js
客户端是火狐这应允许的XMLHttpRequest对象可以访问不同的端口只要服务器用'Access-Control-Allow-Origin头'来表示这一点。
参考
http://www.w3.org/TR/cors/#access-control-allow-origin-response-header
CouchDB cross-domain access from XMLHttpRequest?
答案后通过MKroenert
我升级到CouchDB的1.4.0版本,并适应了local.ini文件允许CORS (C:\ Program Files \ Apache Software Foundation \ CouchDB \等\ CouchDB的\ local.ini)
[httpd]
enable_cors = true
[cors]
origins = *
更多关于 http://wiki.apache.org/couchdb/CORS 特别是如何限制访问。
3.12.1。启用CORS http://docs.couchdb.org/en/latest/configuring.html
然后在琥珀Smalltalk的工作区重新启动CouchDB的服务下面的代码片段工作正常后
| req colordict mimeType |
colordict := HashedCollection new.
colordict at: 'red' put: 'rot'.
colordict at: 'blue' put: 'blau'.
colordict at: 'yellow' put: 'gelb'.
req := XMLHttpRequest new.
req open: 'PUT'
url: 'http://localhost:5984/components/test2' asynchronous: false.
mimeType :='application/json'.
req setRequestHeader: 'Content-Type' mimeType: mimeType.
req send: (JSON stringify: colordict).
req responseText
A '为printit' 还给
'{"ok":true,"id":"test2","rev":"1-8d2356ebdbabdd87a35e0ae3b137bdb5"}
'
谢谢你,这是你的情况1,我已经增加了更多的细节问题。在参考资料部分,我将另一个问题与链接Apache服务文件连接到couchDB(所有本地主机)相关联。 –
在设置方面,情况1。 couchdb在端口5984上运行,琥珀色在端口4000上运行。我需要告诉琥珀色服务器的页面允许XMLHttpRequest访问端口5984.所以在解决方案的情况下,它似乎是你的情况2;我必须配置琥珀色服务器。 –
@Hannes:然后,您必须配置CouchDB服务器,以提供您所链接问题中建议的“Control-Allow-Origin”标头。由于网页未在CouchDB端口上提供,因此CouchDB不允许连接,而不允许连接琥珀色服务器。 – MKroehnert