Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libcurl in C# and .NET

Tags:

c#

.net

libcurl

I’m a PHP developer, my current job is maintaining a few web sites. So I have some free time and thoughts about developing some GUI applications using the c# language and .NET platform. Implementation of this applications requires libcURL functionality.

Are there any .net classes or third-party libs in c#, that can provide me with the same functionality as libcurl in PHP ?

Sorry for my bad English…

like image 752
user304479 Avatar asked Dec 20 '25 08:12

user304479


1 Answers

Yes, the HttpWebRequest and HttpWebResponse classes make it amazingly simple to grab web content from a C# app.

Here's a little snippet of code where I was grabbing a clock time from a webpage:

    private const string URL = "http://housing.udayton.edu/php/lottery/clock.php";
    private const string StartString = "<p align=\"center\"><b>";
    private const string EndString = "</b>";
    private DateTime getTime()
    {
        HttpWebResponse resp = HttpWebRequest.Create(URL).GetResponse() as HttpWebResponse;
        StreamReader reader = new StreamReader(resp.GetResponseStream());
        String data = reader.ReadToEnd();

        int startIndex = data.IndexOf(StartString) + StartString.Length;
        int endIndex = data.IndexOf(EndString, startIndex);
        String time = data.Substring(startIndex, (endIndex-startIndex)-4);

        return DateTime.Parse(time);
    }

Here's a good article that will help you as well:

http://www.csharp-station.com/HowTo/HttpWebFetch.aspx

Of course, nothing is stopping you from actually using libcurl in your .NET application:

http://curl.haxx.se/libcurl/dotnet/

like image 164
Jonathon Reinhart Avatar answered Dec 22 '25 20:12

Jonathon Reinhart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!