Ionic:预检响应中的Access-Control-Allow-Headers不允许请求标头字段标记

时间:2016-12-22 12:44:03

标签: angularjs ionic-framework

使用$ http GET从Ionic app调用Wordpress REST API失败并显示错误:

>>> sentenceData = sqlContext.read.load('file://sample1.csv', format='com.databricks.spark.csv', header='true', inferSchema='true')
>>> sentenceData.show(truncate=False)
+---+---------------------------+
|key|desc                       |
+---+---------------------------+
|1  |Virat is good batsman      |
|2  |sachin was good            |
|3  |but modi sucks big big time|
|4  |I love the formulas        |
+---+---------------------------+


Expected Output
---------------

>>> sentenceData.show(truncate=False)
+---+-------------------------------------+
|key|desc                                 |
+---+-------------------------------------+
|1  |[Virat,is,good,batsman]              |
|2  |[sachin,was,good]                    |
|3  |....                                 |
|4  |...                                  |
+---+-------------------------------------+

我注意到请求标头有:

XMLHttpRequest cannot load http://mywordpressdomain.com/wp-json/wp/v2/categories. Request header field token is not allowed by Access-Control-Allow-Headers in preflight response.

我尝试删除$ http get请求中的标题。

Access-Control-Request-Headers:token

但是Access-Control-Request-Headers:令牌仍然存在于请求标头中。看起来像标题没有效果。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

在开发set skipAuthorization时,在本地主机上没有与http请求相关的任何CORS问题:true ...就这样做:

' $ HTTP({   方法:' GET',   网址:' http://yoururl.com/yourrequest',   skipAuthorization:true })'