Win32でネイティブC/C++用の「ハイレベル」HTTPライブラリはありませんか、間違った場所を探していますか?Win32のネイティブC/C++用のハイレベルHTTPクライアントライブラリ
「高レベル」とは、.NETフレームワークとほぼ同じ抽象度のC++でHTTP Webリクエスト/レスポンスを可能にするAPIを意味します(ただし、C++/CLIを使用することはオプションではありません私のために)。
.NETを使用せずにWin32でC/C++でこれを(ほぼ同じ量のコードで)実行する方法は?参考までに、私は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;
}
}
}
}
重複:http://stackoverflow.com/questions/822581/what-c-library-for-http-client –