在Win32中是否沒有用於本地C/C++的「高級」HTTP庫?或者我只是在錯誤的位置查找? 「高級」我的意思是一個API,它允許我在C++中執行HTTP Web請求/響應,並且與.NET框架具有「大致相同」的抽象級別(但請注意,使用C++/CLI不是一種選擇爲了我)。用於Win32中的本地C/C++的高級HTTP客戶端庫
如何在不使用.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 – 2009-07-14 08:43:50