• 03-01-2023, 16:18:08
    #1
    Flutter Web ile yaptığım panelde Flutter Cors hatası almaktayım. Php koduna gerekli eklemeleri yaptım ancak api 'a istek gönderince halen hata alyorum

    Console'da aldığım hata:
    Çapraz köken isteği engellendi: Aynı Köken İlkesi, https://api.deneme.net/saveQuestion.php üzerindeki uzak kaynağın okunmasına izin vermiyor. (Sebep: CORS başlangıç yanıtındaki ‘Access-Control-Allow-Headers’ CORS üstbilgisine göre ‘content-type’ üstbilgisine izin verilmiyor.)


    Eklediğim php kodu
    <?php
    header('Access-Control-Allow-Origin: *');
    header('Accept: */*');
    header('Access-Control-Allow-Methods: GET, POST');
    header("Access-Control-Allow-Headers: X-Requested-With");
    header('Content-Type: application/json; charset=utf-8');

    Sorunum çözülmedi yardımcı olabilir misiniz?
  • Kabul Edilen Cevap
    • 1 Beğeni
      header('Access-Control-Allow-Origin: *');
      header('Accept: */*');
      header('Access-Control-Allow-Credentials: TRUE');
      header('Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT');
      header("Access-Control-Allow-Headers: Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
      üstteki kodun php'si bu hocam
  • 03-01-2023, 16:22:36
    #2
    header('Content-Type: application/json; charset=utf-8');
    şu satırı kaldırıp yeniden dener misiniz hocam?
  • 03-01-2023, 16:24:33
    #3
    Mhmmd adlı üyeden alıntı: mesajı görüntüle
    header('Content-Type: application/json; charset=utf-8');
    şu satırı kaldırıp yeniden dener misiniz hocam?
    hala aynı hocam

    şöyle birşey buldum ama php'ye nasıl eklenir bu

    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Credentials", "true");
    response.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
    response.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
  • 03-01-2023, 16:27:36
    #4
    Bu cevap, konu sahibi tarafından kabul edilebilir bir cevap olarak işaretlendi.
    header('Access-Control-Allow-Origin: *');
    header('Accept: */*');
    header('Access-Control-Allow-Credentials: TRUE');
    header('Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT');
    header("Access-Control-Allow-Headers: Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
    üstteki kodun php'si bu hocam
  • 03-01-2023, 16:27:57
    #5
    Mhmmd adlı üyeden alıntı: mesajı görüntüle
    header('Access-Control-Allow-Origin: *');
    header('Accept: */*');
    header('Access-Control-Allow-Credentials: TRUE');
    header('Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT');
    header("Access-Control-Allow-Headers: Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
    üstteki kodun php'si bu hocam

    tamamdır hocam düzeldi ) çok teşekkürler
    <?php
    header('Access-Control-Allow-Origin: *');
    header('Accept: */*');
    header('Access-Control-Allow-Methods: GET,HEAD,OPTIONS,POST,PUT');
    header("Access-Control-Allow-Headers: Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
    header('Content-Type: application/json; charset=utf-8');