Wysokiej klasy biblioteka klienta HTTP dla natywnego C / C ++ w Win32
Czy nie ma „wysokiego poziomu” bibliotek HTTP dla rodzimego C / C ++ w Win32 lub po prostu szukam w niewłaściwych miejscach?
Przez „high-level” rozumiem API, które pozwala mi wykonywać żądania / odpowiedzi HTTP w C ++ z „mniej więcej tym samym” poziomem abstrakcji co framework .NET (ale pamiętaj, że używanie C ++ / CLI nie jest dla mnie rozwiązaniem).
Jak zrobić coś takiego (z taką samą ilością kodu) w C / C ++ w Win32 bez użycia .NET? Jako odniesienie, dołączam próbkę kodu, aby pokazać, jak bym to zrobił w C #.
byte[] fileBytes = null;
bool successfulDownload = false;
using (WebClient client = new WebClient())
{
WebProxy proxy = WebProxy.GetDefaultProxy();
client.Proxy = proxy;
tryAgain:
try
{
fileBytes = client.DownloadData(fileUrl);
successfulDownload = true;
}
catch (WebException wEx)
{
if (wEx.Response != null && wEx.Response is HttpWebResponse)
{
string username = null, password = null;
bool userCanceled = false;
HttpStatusCode statusCode = ((HttpWebResponse)wEx.Response).StatusCode;
switch (statusCode)
{
case HttpStatusCode.ProxyAuthenticationRequired:
// This is just a convenience function defined elsewhere
GetAuthenticationCredentials(fileUrl, true,
out username, out password, out userCanceled);
if (!userCanceled)
{
client.Proxy.Credentials = new NetworkCredential(username, password);
goto tryAgain;
}
break;
case HttpStatusCode.Unauthorized:
// This is just a convenience function defined elsewhere
GetAuthenticationCredentials(fileUrl, false,
out username, out password, out userCanceled);
if (!userCanceled)
{
client.Credentials = new NetworkCredential(username, password);
goto tryAgain;
}
break;
}
}
}
}