任何人都可以在這個函數中找到問題嗎? 我的應用程序提出了幾個請求,如果第一個請求使用SSL,某些計算機上的應用程序崩潰(在我的4臺計算機+ vmware上它可以正常運行而不會崩潰)。Wininet C++的問題
這裏是代碼
char Buffer[1024];
DWORD dwRead;
string data;
string Request(string method, string host, string file, string headers,
string post, bool debug, bool SSL)
{
HINTERNET hSession, hDownload, hRequest;
DWORD flag;
DWORD port;
data.empty();
//SSL or not + flag :)
if (SSL)
{
port = INTERNET_DEFAULT_HTTPS_PORT;
flag = INTERNET_FLAG_SECURE; // FLAG_SECURE
}
else
{
port = INTERNET_DEFAULT_HTTP_PORT;
flag = INTERNET_FLAG_RELOAD; //FLAG_RELOAD
}
char * postdata;
postdata = new char[post.size() + 1];
strcpy(postdata, post.c_str());
char * headersdata;
headersdata = new char[headers.size() + 1];
strcpy(headersdata, headers.c_str());
//Actual request
hSession
= InternetOpen(
"Mozilla/5.0 (Windows; U; Windows NT 6.1; sl; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11",
INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (hSession)
{
hDownload = InternetConnect(hSession, host.c_str(), port, NULL, NULL,
INTERNET_SERVICE_HTTP, 0, 0);
if (hDownload)
{
hRequest = HttpOpenRequest(hDownload, method.c_str(), file.c_str(),
"HTTP/1.1", NULL, NULL, flag, 0);
if (hRequest)
{
if (strlen(headersdata) && strlen(postdata))
{
HttpSendRequest(hRequest, headersdata, strlen(headersdata),
postdata, strlen(postdata));
}
else
{
HttpSendRequest(hRequest, NULL, 0, NULL, 0);
}
}
}
}
//Writing HTML response in data buffer
while (InternetReadFile(hRequest, Buffer, sizeof(Buffer), &dwRead))
{
if (dwRead == 0)
{
break;
}
Buffer[dwRead] = 0;
data += Buffer;
}
//Debug :)
if (debug)
{
ofstream dbgfile;
dbgfile.open("debug.html");
dbgfile << data;
dbgfile.close();
}
//Close handles
InternetCloseHandle(hSession);
InternetCloseHandle(hDownload);
InternetCloseHandle(hRequest);
return data;
}
感謝。
發生崩潰時發生了什麼錯誤?訪問違規?其他一些錯誤代碼? – 2011-02-03 10:49:10
錯誤是**此應用程序已要求運行時以不尋常的方式終止它。** 太糟糕了,它不在這裏發生,所以我可以調試:( – pwnu91 2011-02-03 10:51:09