一个使用WebRequest调用本地文件的写法


   string cookie=NULL,headers; 
   char post[],result[]; 
   int res; 
   string google_url=服务器地址+跟踪主账号+".csv"; 
   ResetLastError(); 
   int timeout=5000; //--- Timeout below 1000 (1 sec.) is not enough for slow Internet connection
   res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers); 
   if(res==-1) 
     { 
      Print("Error in WebRequest. Error code  =",GetLastError()); 
      //--- Perhaps the URL is not listed, display a message about the necessity to add the address
     } 
   else
      { 
      //--- Load successfully
      PrintFormat("The file has been successfully loaded, File size =%d bytes.",ArraySize(result)); 
      //--- Save the data to a file
      int filehandle=FileOpen(跟踪主账号+".csv",FILE_WRITE|FILE_BIN); 
      //--- Checking errors
      if(filehandle!=INVALID_HANDLE) 
        { 
         //--- Save the contents of the result[] array to a file
         FileWriteArray(filehandle,result,0,ArraySize(result)); 
         //--- Close the file
         FileClose(filehandle); 
        } 
      else Print("Error in FileOpen. Error code=",GetLastError()); 
     } 
   Print(res);
本博客所有文章如无特别注明均为原创。作者:天泓评测
分享到:更多

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)