My application(A) needs to upload files by AJAX (Fineuploader library) to my subdomain(B) (physically other server).
What is my solution: set headers on B to allow requests from A. See this code of controller action:
public function imageAction()
{
$this->_response->setHeader('Access-Control-Allow-Origin', 'http://' . Zend_Registry::get('config')->main_server->path);
$this->_response->setHeader('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');
$this->_helper->json(array('test'));
}
Then I try to call this action by ajax from A. Request has the next headers:
Request URL:http://sub.domain.dev/upload/image
Request Method:OPTIONS
Status Code:403 Forbidden
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Access-Control-Request-Headers:access-control-allow-origin, x-mime-type, origin, x-requested-with, cache-control, x-file-name, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:sub.domain.dev
Origin:http://domain.dev
Referer:http://domain.dev
What I have done wrong? Thanks.
P.S. When I send request with these headers:
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Content-Length:0
Host:sub.domain.dev
Origin:http://domain.dev
Pragma:no-cache
Referer:http://domain.dev
Tho I think that problem in headers, sended by server.