我試圖用C++控制檯創建一個基本的「登錄」系統。使用PHP來確認用戶信息,C++將簡單地檢索PHP文件輸出的數據。讀取文件時在線計算文件的字節數
我需要C++代碼來在線讀取文件末尾並停止。我正在使用的代碼在文件末尾計算額外的字節數。
INT主要(){
HINTERNET connect = InternetOpenA("LoginCheckUserAgent 0.0.1v (compatible; harmless;)", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!connect){
cout << "Connection Failed or Syntax error";
return 0;
}
HINTERNET OpenAddress = InternetOpenUrlA(connect, "http://localhost/login/check.php?username=admin&password=admin", NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION, 0);
if (!OpenAddress)
{
DWORD ErrorNum = GetLastError();
cout << "Failed to open URL \nError No: " << ErrorNum;
InternetCloseHandle(connect);
return 0;
}
char DataReceived[4096];
DWORD NumberOfBytesRead = 0;
while (InternetReadFile(OpenAddress, DataReceived, 4096, &NumberOfBytesRead) && NumberOfBytesRead)
{
cout << DataReceived;
}
InternetCloseHandle(OpenAddress);
InternetCloseHandle(connect);
cin.get();
return 0;
}
上面的代碼給我:ABC123 |||||||||||等。(直到達到4096個字節) 我想讓它給我:abc123 我需要閱讀「http://localhost/login/check.php?username=admin&password=admin」的內容,沒有額外的字節。我提供的代碼嘗試讀取4096個字節。
我知道我可以只設置4096爲1或者什麼的,只能用PHP來回復1個字節。但我希望PHP腳本能夠隨時改變數據,所以我不能僅僅假設我要處理的字節數。
我不需要任何人來修復代碼,我只是想知道如何才能確定我要讀取的字節,然後讓我的腳本將它讀到這些字節的末尾。所以我不會收到不需要的字節。
對不起如果我做了任何混淆。
你覺得'NumberOfBytesRead'存儲? – 2015-02-24 01:07:18