FSharpData Http.RequestString不会处理" Set-Cookie"在回复标题中?

时间:2015-05-29 22:20:05

标签: f# f#-data

更新 我发现问题是由Http.fs中的第810行引起的。

let cookies = Map.ofList [ for cookie in cookieContainer.GetCookies uri |> Seq.cast<Cookie> -> cookie.Name, cookie.Value ]  

uri以https开头。但是,Cookie ObFormLoginCookie添加了以http开头的域名,因为Cookie中没有secure。不应该使用https请求使用所有Cookie(包括哪些域名不是https)?

以下是在网站上发出两个请求的可测试代码。

open FSharp.Data.HttpRequestHeaders
open System.Configuration
open System.Net
open FSharp.Data
open System
open System.Web
open System.Reflection

let headers = [ 
    UserAgent ConfigurationManager.AppSettings.["UserAgent"]
    Accept "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" 
    KeepAlive "true"
    ]
let customized (req : HttpWebRequest) = 
    //req.Proxy <- WebProxy(ConfigurationManager.AppSettings.["Proxy"], true)
    req.AllowAutoRedirect <- false
    req
let cc = CookieContainer()

let printCc (cc:CookieContainer) =
    let cs = cc.GetType().InvokeMember("m_domainTable", BindingFlags.NonPublic ||| BindingFlags.GetField ||| BindingFlags.Instance, null, cc, [||]) :?> System.Collections.Hashtable
    for x in cs.Keys do 
        let s = string x
        let x = if s.StartsWith(".") then s.Substring(1, s.Length - 1) else s
        let cookie = cc.GetCookies(new Uri(sprintf "https://%s/" x))
        printfn "%s:" s
        for y in cookie do
            printfn "Name=%s; Value=%s; Domain=%s" y.Name (sprintf "%s..." (y.Value.Substring(0, 7))) y.Domain
        printfn ""
    printfn "-------------"

let url = "https://usbtrustgateway.usbank.com/portal/login.do"
let h1 = Http.RequestString(url, httpMethod = "GET", cookieContainer = cc, headers = headers, customizeHttpRequest = customized)
printfn "Url: %s\n" url
printCc cc
let url = "https://usbtrustgateway.usbank.com/portal/"
let h2 = Http.RequestString(url, httpMethod = "GET", cookieContainer = cc, headers = headers, customizeHttpRequest = customized)
printfn "Url: %s\n" url
printCc cc

如果在配置文件中使用fiddler或设置system.diagnostics,则显示实际的原始响应主体。

第一次请求:

{
Pragma: private,No-cache
Content-Language: en-US
Content-Length: 0
Cache-Control: private,no-cache,no-store,max-age=0
Content-Type: text/html
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: https://usbtrustgateway.usbank.com/portal/
Server: 
X-Powered-By: Servlet/3.0,ASP.NET
X-Frame-Options: SAMEORIGIN
Date: Fri, 29 May 2015 22:05:40 GMT
Connection: keep-alive
Set-Cookie: ObSSOCookie=j%2BD73a9JpTHVgo%2FmepgXoObiJZQjqGiFvHhl6Iak9Khzk64RVjXFMDKvqo3wVbKV2MFOs2iHKTy5RxfoSKt4P3OpO8UIM8j6XLZZeKKLUjtL%2FlbKNj%2FwJx13pBBDKwe9X2pU%2FtSjY%2BcfnUy%2B%2B6gJ%2Bab1XW%2B9mQrcw%2FycBNa8kaTYPgU1isboEuSLh3DL6UBTjQbQhEBAvAFr9LlIF46kmzsHXQJFVvb2XsqKsaVIRNJ14EY%2BQgh3vgIEzYV8qW%2FjoidjR7S2tthfn%2BOlKli3w3owoQfcLGKj03H%2FHco6qBtoy8gGJambhE0HMGbuBsQvsNuUftwvYqeKzkUaHIiAm%2FUZh2KppsSvDtk3zdlwJS7Y%2FT1m9t7cj6nUv7Ld%2Bllp;secure; httponly; path=/; domain=.usbank.com,JSESSIONID_TGP=0000_qOg8VF7q5KeUVSHce9FCPX:-1; Path=/; HttpOnly,AidLoginSetup=readyToLogin,usbtrustgateway=!PZhxyd/9XT6sqGcZkYV27O1F5Kg1NlFKahd7AKax4J5mzSI...}

第二个请求(请注意,返回Set-Cookie: ObFormLoginCookie):

{
X-Frame-Options: SAMEORIGIN
Connection: keep-alive
Content-Length: 0
Date: Fri, 29 May 2015 22:05:40 GMT
Location: /portal/login.do
Set-Cookie: ObFormLoginCookie=wh%3Dusbtrustgateway.usbank.com%20wu%3D%2Fportal%2F%20wo%3D1%20rh%3Dhttps%3A%2F%2Fusbtrustgateway.usbank.com%20ru%3D%252Fportal%252F; path=/access/oblix/apps/webgate/bin/webgate.dll
Server: 
X-Powered-By: ASP.NET
}

但是,程序输出如下所示。它表明ObFormLoginCookie的Set-Cookie没有保存在cookie容器中?

Url: https://usbtrustgateway.usbank.com/portal/login.do

.usbank.com:
Name=ObSSOCookie; Value=RzHAZfS...; Domain=.usbank.com

.usbtrustgateway.usbank.com:
Name=JSESSIONID_TGP; Value=0000yOl...; Domain=usbtrustgateway.usbank.com
Name=usbtrustgateway; Value=!4iZ5aX...; Domain=usbtrustgateway.usbank.com
Name=JSESSIONID_TGP; Value=0000yOl...; Domain=usbtrustgateway.usbank.com
Name=AidLoginSetup; Value=readyTo...; Domain=usbtrustgateway.usbank.com
Name=usbtrustgateway; Value=!4iZ5aX...; Domain=usbtrustgateway.usbank.com
Name=ObSSOCookie; Value=RzHAZfS...; Domain=.usbank.com

usbtrustgateway.usbank.com:
Name=JSESSIONID_TGP; Value=0000yOl...; Domain=usbtrustgateway.usbank.com
Name=usbtrustgateway; Value=!4iZ5aX...; Domain=usbtrustgateway.usbank.com
Name=JSESSIONID_TGP; Value=0000yOl...; Domain=usbtrustgateway.usbank.com
Name=AidLoginSetup; Value=readyTo...; Domain=usbtrustgateway.usbank.com
Name=usbtrustgateway; Value=!4iZ5aX...; Domain=usbtrustgateway.usbank.com
Name=ObSSOCookie; Value=RzHAZfS...; Domain=.usbank.com

-------------
Url: https://usbtrustgateway.usbank.com/portal/

.usbank.com:
Name=ObSSOCookie; Value=RzHAZfS...; Domain=.usbank.com

.usbtrustgateway.usbank.com:
Name=JSESSIONID_TGP; Value=0000yOl...; Domain=usbtrustgateway.usbank.com
Name=usbtrustgateway; Value=!4iZ5aX...; Domain=usbtrustgateway.usbank.com
Name=JSESSIONID_TGP; Value=0000yOl...; Domain=usbtrustgateway.usbank.com
Name=AidLoginSetup; Value=readyTo...; Domain=usbtrustgateway.usbank.com
Name=usbtrustgateway; Value=!4iZ5aX...; Domain=usbtrustgateway.usbank.com
Name=ObSSOCookie; Value=RzHAZfS...; Domain=.usbank.com

usbtrustgateway.usbank.com:
Name=JSESSIONID_TGP; Value=0000yOl...; Domain=usbtrustgateway.usbank.com
Name=usbtrustgateway; Value=!4iZ5aX...; Domain=usbtrustgateway.usbank.com
Name=JSESSIONID_TGP; Value=0000yOl...; Domain=usbtrustgateway.usbank.com
Name=AidLoginSetup; Value=readyTo...; Domain=usbtrustgateway.usbank.com
Name=usbtrustgateway; Value=!4iZ5aX...; Domain=usbtrustgateway.usbank.com
Name=ObSSOCookie; Value=RzHAZfS...; Domain=.usbank.com

-------------

0 个答案:

没有答案