2017-04-27 71 views
0

我正在使用request與NodeJS,我想將cookie保存爲JSON。根據文檔,我使用tough-cookie-filestore並傳入jar選項。如何獲取請求將cookies保存爲JSON和tough-cookie-filestore?

我事先在磁盤上創建了文件,然後發出一個我知道返回cookie的請求。但由於某種原因,我收到響應後,我創建的用於存儲Cookie的空文件保持空白。

我應該明確告訴請求提交cookie到文件,還是應該是自動的?

// using a promise-enabled version of promise 
return request({ 
    url: url, 
    jar: new FileCookieStore(myfile) 
}); 

回答

0

我發現我的錯誤。我應該這樣使用它:

// using a promise-enabled version of promise 
return request({ 
    url: url, 
    jar: request.jar(new FileCookieStore(myfile)) 
});