当我尝试从angular 6应用程序访问webhdfs时,出现如下错误。在我看来,我几乎什么都试过了,包括改变电脑的设置 core-site.xml
以及 hdfs-site.xml
不幸的是没有积极的结果。显然,很可能需要正确配置hadoop。有人知道我怎么解决这个问题吗?
[Error] Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin.
[Error] XMLHttpRequest cannot load http://192.168.0.16:9870/webhdfs/v1/user/myuser/myfile.csv?op=CREATE&user.name=myuser&createflag=&createparent=true&overwrite=false due to access control checks.
[Error] Failed to load resource: Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin. (myfile.csv, line 0)
4条答案
按热度按时间pieyvz9o1#
在core-site.xml中,如果没有,请添加此项。。。
sgtfey8w2#
您应该配置hdfs-site.xml,并添加配置
pgx2nnw83#
从文档中:
要启用跨源支持(cors),请设置以下配置参数:
将org.apache.hadoop.security.httpcrossoriginfilterinitializer添加到core-site.xml中的hadoop.http.filter.initializers。您还需要在core-site.xml中设置以下属性-
hadoop.http.cross-origin.enabled=真
hadoop.http.cross-origin.allowed-origins=*
hadoop.http.cross-origin.allowed-methods=get、post、head、delete和options
hadoop.http.cross-origin.allowed-headers=x-requested-with,内容类型,接受,来源
hadoop.http.cross-origin.max-age=1800
webghufk4#
必须将这些属性附加到此文件中
etc/hadoop/core-site.xml
```hadoop.http.cross-origin.enabled
false
hadoop.http.cross-origin.allowed-origins
*
hadoop.http.cross-origin.allowed-methods
GET,POST,HEAD
hadoop.http.cross-origin.allowed-headers
X-Requested-With,Content-Type,Accept,Origin
hadoop.http.cross-origin.max-age
1800