2010-10-20 240 views
0

我想在包含身份驗證令牌的客戶端上放置一個cookie。在用他們的憑證登錄後,他們可以發送令牌而不是憑證,直到服務器確定令牌已過期。Cookies - 存儲身份驗證令牌

下面是cookie的構造函數。我正在使用restlets,並且不確定要將「路徑」和「域」設置爲什麼。這些領域的目的是什麼?另外,如果我將'secure'設置爲'true',那麼這是否意味着如果連接不是https,它不會傳輸cookie?

public CookieSetting(int version, 
        String name, 
        String value, 
        String path, 
        String domain, 
        String comment, 
        int maxAge, 
        boolean secure, 
        boolean accessRestricted); 

//'secure' - Indicates if cookie should only be transmitted by secure means. 
//'accessRestricted' - Indicates whether to restrict cookie access to untrusted parties. 
// Currently this toggles the non-standard but widely supported HttpOnly cookie parameter. 

回答

1

例如,如果您設置域= xyz.com,路徑= /應用程序和安全= true時,瀏覽器會發送cookie調用https://xyz.com/app/時...

如果安全= TRUE時,當使用http://xyz.com/app URL時,cookie將不會被髮送。

+0

因此,您可以爲不同於創建Cookie的域設置Cookie,但默認情況下Cookie是由瀏覽器爲當前域創建的? – 2010-10-20 22:35:02

+0

是的,這應該工作。通常,您應該能夠將域設置爲當前域的子域。瀏覽器安全性在某些情況下可能會阻止爲其他域設置Cookie。 – 2010-10-20 22:45:11

相關問題