Ankündigung

Einklappen
Keine Ankündigung bisher.

Problem mit header() und CORS

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Problem mit header() und CORS

    Hallo Leute,
    ich habe mich hier im Forum angemeldet da ich mit einem Problem partout nicht weiterkomme.
    In meinem Versuchsszenario möchte ich von lokaleDomain einen JavaScript Request auf localhost durchführen.
    Meine Versuche mit CORS sind bisher nicht von Erfolg gekrönt worden.
    Ich entwickle unter Windows 7 mit XAMPP (PHP 5.4.x) habe aber zum Testen auch schon XAMPP mit PHP 5.6 eingesetzt.
    Das .php Skript auf localhost beginnt mit folgendem Code
    PHP-Code:
        header("Access-Control-Allow-Origin: *");
        
    header('Access-Control-Allow-Credentials: true');
        
    header('Access-Control-Max-Age: 86400');

        if (isset(
    $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) {
            
    header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
        }
        if (isset(
    $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
            
    header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
        } 
    Der FireFox Browser meldet allerdings das der Request auf Grund der Same-Origin-Policy nicht erlaubt ist.
    Beim Betrachten des Antwort Headers im FireBug ist mir aufgefallen dass "Access-Control-Allow-Origin" zu "access-control-allow-origin" wurde.
    Kann die Kleinschreibung das Problem sein ? Wenn ich header("Access-Control-Allow-Origin-5: *"); oder header("BLAblaBLA: *); eintippe,
    wird der String nicht in Klienbuchstaben umgewandelt.
    Hier der Anfrage Header
    Code:
    OPTIONS / HTTP/1.1
    Host: 127.0.0.1
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: de,en-US;q=0.7,en;q=0.3
    Accept-Encoding: gzip, deflate
    Origin: http://localhost
    Access-Control-Request-Method: POST
    Connection: keep-alive
    Pragma: no-cache
    Cache-Control: no-cache
    Hier der Antwort Header
    Code:
    HTTP/1.1 400 Bad Request
    Date: Mon, 04 May 2015 09:32:56 GMT
    Server: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
    X-Powered-By: PHP/5.4.7
    Set-Cookie: oc5766a6283d=9btuepn3dkdl9lru06ero05q20;
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    X-XSS-Protection: 1; mode=block
    x-content-type-options: nosniff
    X-Frame-Options: Sameorigin
    content-security-policy: default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src *; img-src *; font-src 'self' data:; media-src *
    X-Robots-Tag: none
    access-control-allow-origin: *
    Access-Control-Allow-Credentials: true
    access-control-max-age: 86400
    access-control-allow-methods: GET, POST
    Content-Length: 40
    Connection: close
    Content-Type: text/html; charset=utf-8
    Gruß Till

  • #2
    Groß-/kleinschreibung spielt bei Headern keine Rolle.
    Könnte "localhost" sein, das Probleme macht. Versuch mal mit 'nem anderen Namen.

    Grüße.

    Kommentar

    Lädt...
    X