簡體   English   中英

從HTTP請求角度發送cookie到PHP

[英]angular send cookies from http request to php

所以這個問題問了好幾次,但我仍然無法弄清楚。 我正在從角度應用程序向php服務發送http請求。 並且我需要訪問從瀏覽器設置的cookie。 我知道要從php服務訪問cookie,我必須在我的http請求中設置withCredentials 但隨后又出現了通配符錯誤。

這是http請求

$http({
    url : $scope.urlDomain+ "setting/getAll?skip=0&take=10&orderby=asc",
    method :"POST",
    headers : {
        securityToken : "1124"
    },
    withCredentials: true 
})

我已經在我的php文件中設置了標頭

header("Access-Control-Allow-Origin: * ");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT,POST, GET, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: origin, x-requested-with, content-type, securityToken");

這是錯誤

XMLHttpRequest cannot load http://localhost/services/getAll?skip=0&take=10&orderby=asc. Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost' is therefore not allowed access. The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute

我堅持了這一天,仍然無法弄清楚。 多謝你們

您不能使用header("Access-Control-Allow-Origin: * "); 啟用withCredentials ,必須指定一個這樣的域:

header("Access-Control-Allow-Origin: 127.0.0.1");
header("Access-Control-Allow-Origin: domain2");
header("Access-Control-Allow-Origin: domain3");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM