Bug 15935 - WebClient with Cookie support not working with async methods
Summary: WebClient with Cookie support not working with async methods
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-11-05 09:45 UTC by matthi.d
Modified: 2013-11-05 09:45 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description matthi.d 2013-11-05 09:45:08 UTC
When using a simple CookieWebClient (code attached on the end) UploadValuesTaskAsync seems to ignore the CookieContainer property.

I used the following lines of code (within an f# async workflow)
//let! result = client.UploadValuesTaskAsync(login |> getAbsoluteUrl, "POST", postData |> postFromSeq) |> Async.AwaitTask
//let result = client.UploadValues(login |> getAbsoluteUrl, "POST", postData |> postFromSeq)

On the .NET Framework both lines work as expected. On mono only the second line works and the first line is giving me the result I expect when CookieContainer is empty or ignored.


Here is the CookieWebClient I'm using (basically a direct F# port of http://stackoverflow.com/a/11523836):




type CookieWebClient(container : CookieContainer) = 
    inherit WebClient()
    let readCookies (r:WebResponse) =
        match  r with
        | :? HttpWebResponse as response ->
            let cookies = response.Cookies            
            container.Add(cookies)
        | _ -> ()

    override x.GetWebRequest address =
        let request = base.GetWebRequest(address)
        match request with
        | :? HttpWebRequest as httpReq -> 
            log.logVerb (fun _ -> L "Setting CookieContainer")
            httpReq.CookieContainer <- container
            httpReq.AutomaticDecompression <- DecompressionMethods.GZip ||| DecompressionMethods.Deflate
        | _ -> ()
        
        request
        
    override x.GetWebResponse(request:WebRequest,  result:System.IAsyncResult) = 
        let response = base.GetWebResponse(request, result)
        readCookies(response)
        response

    override x.GetWebResponse request =
        let response = base.GetWebResponse(request)
        readCookies response
        response

Note You need to log in before you can comment on or make changes to this bug.