@KuzmenkoArtem

Не могу отправить кроссдоменный запрос Apache 2.4?

Клиент js, angular.js
Сервер apache 2.4 + php (openserver)

Пытаюсь кроссдоменно отправить запрос POST запрос с json-ом.

Консоль высылает ошибки
OPTIONS http://testApi.com/test
XMLHttpRequest cannot load http://testApi.com/test. Invalid HTTP status code 405


Сеть. Response Headers
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Accept, X-Requested-Wit, X-Accept-Charset,X-Accept,Content-Type,Accept-Language,Accept-Charset,X-Request-With,Content-Length,Accept,Origin
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin:*
Allow:POST
Cache-Control:no-cache
Connection:close
Content-Length:4519
Content-Type:text/html; charset=UTF-8
Date:Tue, 14 Jul 2015 22:05:26 GMT
Server:Apache/2.4.10 (Win32)


Сеть. Requeste Headers
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,uk;q=0.2
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:testApi.com
Origin:http://clientApi.com
Referer:http://clientApi.com/
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36


Файл .htaccess в корне сайта
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>


    Header add Access-Control-Allow-Origin: *
    Header add Access-Control-Allow-Methods: "GET, POST, PUT, DELETE, OPTIONS"
    Header add Access-Control-Allow-Headers: "Accept, X-Requested-Wit, X-Accept-Charset,X-Accept,Content-Type,Accept-Language,Accept-Charset,X-Request-With,Content-Length,Accept,Origin"
    Header add Access-Control-Allow-Credentials: true


Сам файл конфигурации apache
#-----------------------------------------------#
# Основная конфигурация сервера
#-----------------------------------------------#

%httpcharset%
AcceptFilter            http none
AcceptFilter            https none
AccessFileName          .htaccess
DocumentRoot            "%ssitedir%/"
EnableMMAP              Off
EnableSendfile          Off
ExtendedStatus          On
HostnameLookups         Off
KeepAlive               On
KeepAliveTimeout        10
Listen                  %ip%:%httpport%
Listen                  %ip%:%httpsport%
MaxConnectionsPerChild  %maxrequests%
MaxKeepAliveRequests    100
MaxRanges               200
PidFile                 "%sprogdir%/userdata/temp/httpd.pid"
ScriptInterpreterSource script
ServerName              %ips%
ServerRoot              "%sprogdir%/modules/http/%httpdriver%"
ServerSignature         Off
ServerTokens            OS
ListenBacklog           1024
ThreadLimit             32
ThreadsPerChild         32
ThreadStackSize         8388608
Timeout                 30
UseCanonicalName        Off


#-----------------------------------------------#
# Подключение модулей
#-----------------------------------------------#

LoadModule    access_compat_module    modules/mod_access_compat.so
............. подключение куча подулей, пропустил

PHPINIDir     "%sprogdir%/modules/php/%phpdriver%"
LoadModule    php5_module    "%sprogdir%/modules/php/%phpdriver%/php5apache2_4.dll"

<IfModule reqtimeout_module>
    RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
</IfModule>

#-----------------------------------------------#
# Настройка прав доступа к серверу
#-----------------------------------------------#

<Directory />
    Options +FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>
<Directory "%ssitedir%/*">
    AllowOverride All
    Options -MultiViews +Indexes +FollowSymLinks +IncludesNoExec +Includes +ExecCGI
    Require all granted
</Directory>
<Directory "%sprogdir%/modules/system/html/openserver">
    AllowOverride None
    Options -MultiViews -Indexes -FollowSymLinks -IncludesNoExec -Includes -ExecCGI
    AddDefaultCharset Off
    <IfModule dir_module>
        DirectoryIndex index.php
    </IfModule>
    Require all denied
    Require ip 127.0.0.0/8 ::1/128
    Require ip %ips%
    %allow%Require all granted
</Directory>
<Directory "%sprogdir%/modules/system/html/default">
    AllowOverride None
    Options -MultiViews -Indexes -FollowSymLinks -IncludesNoExec -Includes -ExecCGI
    AddDefaultCharset Off
    <IfModule dir_module>
        DirectoryIndex index.html
    </IfModule>
    Require all granted
</Directory>
<Directory "/cgi-bin">
    AllowOverride None
    Options +ExecCGI
    Require all granted
</Directory>
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>
<IfModule alias_module>
    Alias    /openserver/ "%sprogdir%/modules/system/html/openserver/"
</IfModule>

#-----------------------------------------------#
# Конфигурация сообщений об ошибках
#-----------------------------------------------#
...... этот блок думаю не важен

#-----------------------------------------------#
# Конфигурация MIME
#-----------------------------------------------#
........этот тоже

#-----------------------------------------------#
# Конфигурация Index-а и иконок
#-----------------------------------------------#
..............

#-----------------------------------------------#
# Подключение языков и кодировок
#-----------------------------------------------#
..............

#-----------------------------------------------#
# Конфигурация SSL
#-----------------------------------------------#

AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl

<IfModule ssl_module>
    SSLPassPhraseDialog       builtin
    SSLSessionCache           "shmcb:%sprogdir%/userdata/temp/ssl_scache(512000)"
    SSLSessionCacheTimeout    300
    Mutex                     default
    SSLCryptoDevice           builtin
    SSLRandomSeed startup     builtin
    SSLRandomSeed connect     builtin
    SSLVerifyClient           none
    SSLProtocol               ALL -SSLv2 -SSLv3
    SSLCipherSuite            ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
    SSLHonorCipherOrder       On
    SSLCompression            Off
    SSLCertificateFile        "%sprogdir%/userdata/config/server.crt"
    SSLCertificateKeyFile     "%sprogdir%/userdata/config/server.key"
</IfModule>

#-----------------------------------------------#
# Исключения User Agent
#-----------------------------------------------#
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
#-----------------------------------------------#
# Первичный виртуальный хост "по умолчанию"
#-----------------------------------------------#
<VirtualHost *:%httpport%>
    DocumentRoot    "%sprogdir%/modules/system/html/default"
    ServerName      "default"
    ServerAlias     "default"
    <Location /openserver/server-status>
        SetHandler server-status
        Require all denied
        Require ip 127.0.0.0/8 ::1/128
        Require ip %ips%
        %allow%Require all granted
    </Location>
</VirtualHost>
<VirtualHost *:%httpsport%>
    DocumentRoot    "%sprogdir%/modules/system/html/default"
    ServerName      "default"
    ServerAlias     "default"

    SSLEngine on

    SetEnvIf User-Agent ".*MSIE [1-5].*" \
    nokeepalive ssl-unclean-shutdown \
    downgrade-1.0 force-response-1.0

    SetEnvIf User-Agent ".*MSIE [6-9].*" \
    ssl-unclean-shutdown
</VirtualHost>
#-----------------------------------------------#
# Конец конфигурации хоста "по умолчанию"
#-----------------------------------------------#



#---------------------------------------------#
# Начало блока конфигурации HTTP хоста        #
#---------------------------------------------#
<VirtualHost *:80>

DocumentRoot "C:/OpenServer/domains/testApi.com/public"
ServerName "testApi.com"
ServerAlias "testApi.com" 
<IfModule alias_module>
ScriptAlias /cgi-bin/ "C:/OpenServerOld/domains/testApi.com/public/cgi-bin/"
</IfModule>
<Location /openserver/server-status>
SetHandler server-status
</Location>
</VirtualHost>
#---------------------------------------------#
# Конец блока конфигурации HTTP хоста         #
#---------------------------------------------#


Спасибо!.
  • Вопрос задан
  • 1620 просмотров
Решения вопроса 1
Fesor
@Fesor
Full-stack developer (Symfony, Angular)
Invalid HTTP status code 405


RewriteRule ^ index.php [L]


Вывод, с апачем все хорошо, префлайт запрос добрался до index.php, который не понял что такое OPTIONS и дропнулся с 405-ым статус кодом.

Решение - зависит от того что там внутри. Суть в том что бы index.php отдавал на OPTIONS запрос с заголовками префлайта 200-ый статус код.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы