Có không "cao cấp" thư viện HTTP cho bản C/C++ trong Win32 hay tôi chỉ tìm kiếm ở các vị trí sai?cao cấp thư viện client HTTP cho bản C/C++ trong Win32
Bằng cách "cấp cao" Ý tôi là một API cho phép tôi làm các yêu cầu HTTP web/phản ứng trong C++ với "về cùng một" mức độ trừu tượng như .NET framework (nhưng lưu ý rằng việc sử dụng C++/CLI không phải là một lựa chọn cho tôi).
Làm thế nào để làm điều gì đó như thế này (với khoảng cùng một lượng code) trong C/C++ trong Win32 mà không sử dụng NET? Để tham khảo, tôi bao gồm một mẫu mã để chỉ ra cách tôi làm điều đó trong 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;
}
}
}
}
trùng lặp: http://stackoverflow.com/questions/822581/what-c-library-for-http-client –