2013-05-10 61 views
1

我需要在Ubuntu上配置Apache以考虑POST跨域。如何配置Apache以接受POST跨域

我试图像http://enable-cors.org/server_apache.html

  1. 安装mod_header
  2. 添加报头( '访问控制允许来源:'。$ _ SERVER [ 'HTTP_ORIGIN']); header('Access-Control-Allow-Methods:POST,GET,OPTIONS'); header('Access-Control-Max-Age:1000'); header('Access-Control-Allow-Headers:Content-Type');

但这不起作用。

请求报头:

Accept:*/* 
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3 
Accept-Encoding:gzip,deflate,sdch 
Accept-Language:en-US,en;q=0.8 
Access-Control-Request-Headers:accept, cache-control, origin, x-requested-with, x-file-name, content-type 
Access-Control-Request-Method:POST 
Connection:keep-alive 
Host:xxx.amazonaws.com 
Origin:local.com 
Referer:local.com/test/test.php 
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31 

响应头:

Access-Control-Allow-Methods:POST, GET, OPTIONS 
Access-Control-Allow-Origin:* 
Connection:Keep-Alive 
Content-Encoding:gzip 
Content-Length:27 
Content-Type:text/html Date:Fri, 10 May 2013 10:30:10 GMT 
Keep-Alive:timeout=5, max=100 
Server:Apache/2.2.22 (Ubuntu) Vary:Accept-Encoding X-Powered-By:PHP/5.3.10-1ubuntu3.6 

任何人都可以帮我吗?非常感谢你

+0

你能告诉请求/响应您发送/接收来自服务器?我用来允许CORS的一篇好文章是https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS – 2013-05-10 10:08:01

+0

状态代码:200 OK 请求头文查看源代码 接受:*/* Accept-Charset:ISO -8859-1,utf-8; q = 0.7,*; q = 0.3 接受编码:gzip,deflate,sdch Accept-Language:zh-CN,en; q = 0.8 访问控制请求头:接受,缓存控制,起源,x请求,x文件名,内容类型 访问控制请求方法:POST 连接:保持活动 主持人:xxx.amazonaws.com 来源:http://local.com Referer:http://local.com/test/test.php User-Agent:Mozilla/5.0(Macintosh; Intel Mac OS X 10_8_3)AppleWe bKit/537.31(KHTML,如Gecko)Chrome/26.0.1410.65 Safari/537.31 – ducib 2013-05-10 10:33:22

+0

响应标题:访问控制允许方法:POST,GET,选项 访问控制允许来源:* 连接:保持活动 内容编码:gzip 的Content-Length:27 的Content-Type:text/html的 日期:星期五,2013 5月10日十点30分十秒GMT 保持活动:超时= 5,最大= 100 服务器:Apache /2.2.22(Ubuntu) Vary:Accept-Encoding X-Powered-by:PHP/5.3.10-1ubuntu3.6 – ducib 2013-05-10 10:33:48

回答