masroore / CurlSharp

CurlSharp - .Net binding and object-oriented wrapper for libcurl.
BSD 3-Clause "New" or "Revised" License
182 stars 71 forks source link

easy auth #16

Closed marrrschine closed 8 years ago

marrrschine commented 8 years ago

Hi, I want to wrap my native curl call

curl.exe -i -Uuser:token -O "http://path/to/file.zip"

using CurlSharp.

First question: Do I have to set user and token by

easy.UserAgent = "user";
easy.UserPwd = "token";

in CurlSharp?

Second question: Can you give an example on how to modify OnWriteData to handle my zip file.

Thanks a lot!

masroore commented 8 years ago

@marrrschine: Easiest way to provide authentication data is via the UserPwd property: easy.UserPwd = "user:password";

You can save the downloaded buffer into a stream (file or memory). Once the entire file is downloaded, you may manipulate the zip archive. Pseudo-code:

    public static Int32 OnWriteData(Byte[] buf, Int32 size, Int32 nmemb, Object extraData)
    {
        var nBytes = size*nmemb;
        _stream.Write(buf, nBytes);
        return nBytes;
    }