Win32中用于本机C / C ++的高级HTTP客户端库 [英] High-level HTTP client library for native C/C++ in Win32
问题描述
在Win32中是否没有用于本机C / C ++的高级HTTP库,或者我只是在错误的位置查找?
Are there no "high-level" HTTP libraries for native C/C++ in Win32 or am I just looking in the wrong places?
按高级 我的意思是一个API,它允许我在C ++中使用与.NET框架大致相同的抽象级别来执行HTTP Web请求/响应(但请注意,使用C ++ / CLI不是我的选项)。
By "high-level" I mean an API that lets me do HTTP web requests/responses in C++ with "about the same" abstraction level as the .NET framework (but note that using C++/CLI is not an option for me).
如何在不使用.NET的情况下在Win32中的C / C ++中执行此类操作(具有大约相同数量的代码)?作为参考,我包含一个代码示例,以显示我如何在C#中执行此操作。
How to do something like this (with about the same amount of code) in C/C++ in Win32 without using .NET? As a reference, I include a code sample to show how I'd do it in 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;
}
}
}
}
推荐答案
Win32提供 Internet *
函数。
Win32 provides the Internet*
functions.
http://msdn.microsoft.com/en-us/library/aa385473(VS .85).aspx
你需要做一个(IIRC,我在10年内没有触及这些API) InternetOpenURL
和 InternetReadFile
。
You'll need to do an (IIRC, I haven't touched these APIs in over 10 years) InternetOpenURL
and InternetReadFile
.
这篇关于Win32中用于本机C / C ++的高级HTTP客户端库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!