尽管我付出了最大的努力,但我无法将带有Json数据的Ajax请求发送到远程Web服务器。 我不知道我能用什么其他地方启用CORS并且我的想法已经用完了。
Azure网站应用程序设置:
cors:allowOrigins: *MVC控制器:我安装了NuGet Cors软件包
[EnableCors(origins: "*", headers: "*", methods: "*")]Web.config文件:
<httpProtocol> <customHeaders> <clear /> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol>ExtJs Ajax请求:
Ext.Ajax.request({ url: app.utilities.url, defaultHeaders: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, Authorization,Content-Length, X-Requested-With' }, cors: true, useDefaultXhrHeader: false, params: { jsonData: Ext.util.JSON.encode(formData) }但我仍然得到:跨源请求被阻止:同源策略不允许在{my url}读取远程资源这可以通过将资源移动到同一域或启用CORS来解决。
有什么我想念的吗?
Despite my best efforts I am not able to send an Ajax request with Json data to a remote web server. I do not know what other places I can put enable CORS and am running out of ideas.
Azure Website App Settings:
cors:allowOrigins: *MVC Controller: I had installed the NuGet Cors package
[EnableCors(origins: "*", headers: "*", methods: "*")]Web.config:
<httpProtocol> <customHeaders> <clear /> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol>ExtJs Ajax Request:
Ext.Ajax.request({ url: app.utilities.url, defaultHeaders: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, Authorization,Content-Length, X-Requested-With' }, cors: true, useDefaultXhrHeader: false, params: { jsonData: Ext.util.JSON.encode(formData) }Yet I still get: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at {my url} This can be fixed by moving the resource to the same domain or enabling CORS.
Is there something I am missing?
最满意答案
你会考虑JsonP(带填充的JSON)吗?
http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.data.JsonP
Would you consider JsonP (JSON with Padding)?
http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.data.JsonP
更多推荐
CORS,url,Ajax,cors,电脑培训,计算机培训,IT培训"/> <meta name="descriptio
发布评论