2015-04-29 147 views
1

我有以下代碼,它使用http://fsharp.github.io/FSharp.Data/library/Http.html登錄網站並獲取一些文件。但是,每個頁面都有一個用於設置cookie的jQuery腳本 - $.cookie("Authenticated", 14313432);。我的代碼必須模仿jQuery腳本來設置cc。否則認證將失敗。如何使用F#Data:HTTP Utilities?如何設置cookie?

let cc = CookieContainer() 
let h = Http.RequestString(url, httpMethod = "GET", cookieContainer = cc, headers = headers) // embedded jQuery will set the cookie 
let body = HttpRequestBody.FormValues ["UserName", "xxx"; "Password", "ppp"] 
Http.RequestString(url, body=body, httpMethod="POST", cookieContainer=cc, headers = ... 
let page = Http.RequestString(....) // embedded jQuery script will set the cookie with different value 
let page2 = Http.RequestString(....) // embedded jQuery script will set the cookie with different value 

回答

1

如果我得到你的權利,你不知道如何插入"Authenticated", 14313432作爲一個cookie,但你發現如何使用CookieContainer吧?

CookieContainer僅僅是一個.NET類contiaining Cookie對象,所以這應該做的伎倆:

let cc = CookieContainer() 
let cookie = Cookie ("Authenticated", "14313432") 
cc.Add cookie 
// the rest of your code