"预检的响应具有无效的HTTP状态代码404"

时间:2017-09-19 13:55:12

标签: javascript ajax apache .htaccess http

我反复收到预检错误。我已经尝试了很多方法,除了在同一台服务器上调用API之外什么也没有用。在本地它会产生上述错误。

我尝试更改.htaccess文件以允许" *",并更改了.htaccess中的其他标头设置而没有运气。

在Webpack中,我尝试过设置它们,但没有运气。

我得到的网络响应:

enter image description here

我得到的错误:

enter image description here

我用来调用API的代码

var attendeeRequest = {
  "async": true,
  "crossDomain": true,
  "url": baseUrl + "attendees",
  "method": "GET",
  "headers": {
    "api-key": apiKey,
    "dm": dm,
    "event-id": "",
    "cache-control": "no-cache",
  }
}

$.ajax(attendeeRequest).done(function(response) {
  console.log(response);
});

根.htaccess文件

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html

       # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4\.0[678] no-gzip

       # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

       # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

       # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>

   <IfModule mod_headers.c>
        # Make sure proxies don't deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>

... public_html文件夹中还有另一个htaccess文件。

Public_html .htaccess文件

#system System Redirects
    RewriteEngine on

   RewriteCond %{HTTP_HOST} ^(www.)?url.com$
    RewriteRule !^dotcom/ /dotcom%{REQUEST_URI} [L,NC]
    #RewriteRule /dotcom%{REQUEST_URI} [L,NC]
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

   # otherwise forward it to index.php
    RewriteRule . index.php

   RewriteCond %{HTTP_HOST} ^docs\.url\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.docs\.url\.com$
    RewriteRule ^/?$ "https\:\/\/docs\.url\.com\/" [R=301,L]

#Disable directory listing
    Options -Indexes

#Set header for security
    Header Set X-Content-Type-Options: "nosniff"
    Header set X-Frame-Options DENY
    Header set X-XSS-Protection "1; mode=block"
    Header set Access-Control-Allow-Origin "*"

#Completes Cache-control and Pragma HTTP headers
    <FilesMatch "\.(html|htm|js|css|php)$">
        FileETag None
        <ifModule mod_headers.c>
            Header unset ETag
            Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
            Header set Pragma "no-cache"
            Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
        </ifModule>
    </FilesMatch> 

0 个答案:

没有答案