file1.php
php code $file = d:\\readfileto.txt; $handle = fopen($file, 'r'); $scontent = ''; while(false != ($a = fread($handle, 8080))){//返回false表示已经读取到文件末尾 $scontent .= $a; } fclose($handle); echo $scontent;
vc(输出file1.php):
c/c++ code#include stdafx.h#include #include #include #include #include #pragma comment(lib,wininet.lib) #define data_cache_size 1024*10int main(int argc, char* argv[]){ printf(hello world!\n); int i = 0; char pulr[] = file1.php; hinternet hinternet=::internetopen( http generic, internet_open_type_preconfig, null, null, 0); if (!hinternet) { printf(internetopen\n); system(pause); return 0; } i = 1; hinternet hconnect= ::internetconnect( hinternet, 144.20.80.27, 8080, null, //lpszusername null, //lpszpassword internet_service_http, 0, //dwflags 0 //dwcontext ); if (!hconnect) { printf(internetconnect\n); system(pause); return 0; } hinternet hhttpopenrequest=::httpopenrequest( hconnect, post, pulr, http/1.1, null, 0, internet_flag_reload, 0 ); if (!hhttpopenrequest) { printf(httpopenrequest\n); system(pause); return 0; } char psheader[] = content-type: application/x-www-form-urlencoded \n\r; if (!(httpaddrequestheaders( hhttpopenrequest, psheader, strlen(psheader), http_addreq_flag_replace|http_addreq_flag_add )) ) { printf(httpaddrequestheaders\n); system(pause); return 0; } char *strret=; //yjr|fc|zf|cym|wjf||role1|role2|role3|role4; char pstrcontent[] = username=admin&password=-1; if (! (httpsendrequest( hhttpopenrequest, null, 0, (lpvoid)(lpcstr)pstrcontent, strlen(pstrcontent) )) ) { printf(httpsendrequest\n); system(pause); return 0; } // get the length of the file. dword dwfilesize=0; dword dwlengthbufquery = sizeof(dwfilesize); dword dwindex=0; bool bquery = ::httpqueryinfo(hhttpopenrequest, http_query_content_length |http_query_flag_number, (lpvoid)&dwfilesize/*bufquery*/, &dwlengthbufquery, &dwindex) ; if (!bquery) { printf(httpqueryinfo\n); system(pause); return 0; } // allocate a buffer for the file. char* buffer = new char[dwfilesize+1] ; //由于不允许http写缓存,所以无需循环调用internetreadfile dword dwlength=0; dword dwlengthone=1; bool bread=true; char bufferone[data_cache_size+10]; strcpy(buffer,); while (bread && dwlengthone>0) { strcpy(bufferone,); if (internetreadfile( hhttpopenrequest, bufferone, data_cache_size+1, &dwlengthone ) ) { if (dwlengthone>0) { memcpy(&buffer[dwlength],bufferone,dwlengthone); dwlength+=dwlengthone; //接收数据包的大小和与总数据包大小比较 if (dwlength > dwfilesize) { printf(while\n); system(pause); return 0; } buffer[dwlength]='\0'; } } } buffer[dwlength]='\0'; //to widerchar dword dwsize = multibytetowidechar (cp_acp, 0, buffer, -1, null, 0); wchar *wchr = new wchar [dwsize]; ::multibytetowidechar(cp_acp,mb_err_invalid_chars,buffer,-1, wchr,dwsize); printf(buffer);// wprintf(wchr); delete [] wchr; delete [] buffer; ::internetclosehandle(hhttpopenrequest);hhttpopenrequest=null; ::internetclosehandle(hconnect);hconnect=null; ::internetclosehandle(hinternet);hinternet=null; printf(\n); system(pause); return 0;}
