test_group/ba/web.mq5

80 lines
6.1 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:31:23 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| web.mq5 |
//| Copyright 2018, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
Alert( openlink("https://wlink.ru/fx/in.txt"));
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
// ?> >H81:5
}
string openlink(string url) {
string cookie=NULL,headers;
char post[],result[];
//string url="https://finance.yahoo.com";
//--- 4;O @01>BK A A5@25@>< =5>1E>48<> 4>1028BL URL "https://finance.yahoo.com"
//--- 2 A?8A>: @07@5H5==KE URL (;02=>5 <5=N->!5@28A->0AB@>9:8, 2:;04:0 "!>25B=8:8"):
//--- >1=C;O5< :>4 ?>A;54=59 >H81:8
ResetLastError();
//--- 703@C7:0 html-AB@0=8FK A Yahoo Finance
int res=WebRequest("GET",url,cookie,NULL,500,post,0,result,headers);
if(res==-1)
{
Print("H81:0 2 WebRequest. >4 >H81:8 =",GetLastError());
//--- 2>7<>6=>, URL >BACBAB2C5B 2 A?8A:5, 2K2>48< A>>1I5=85 > =5>1E>48<>AB8 53> 4>102;5=8O
MessageBox("5>1E>48<> 4>1028BL 04@5A '"+url+"' 2 A?8A>: @07@5H5==KE URL 2> 2:;04:5 '!>25B=8:8'","H81:0",MB_ICONINFORMATION);
}
else
{
if(res==200)
{
//--- CA?5H=0O 703@C7:0
PrintFormat("$09; CA?5H=> 703@C65=, @07<5@ %d 109B.",ArraySize(result));
//PrintFormat("03>;>2:8 A5@25@0: %s",headers);
//--- A>E@0=O5< 40==K5 2 D09;
int filehandle=FileOpen("in.txt",FILE_WRITE|FILE_BIN);
if(filehandle!=INVALID_HANDLE)
{
//--- A>E@0=O5< A>45@68<>5 <0AA820 result[] 2 D09;
FileWriteArray(filehandle,result,0,ArraySize(result));
//--- 70:@K205< D09;
FileClose(filehandle);
}
else
Print("H81:0 2 FileOpen. >4 >H81:8 =",GetLastError());
}
else
PrintFormat("H81:0 703@C7:8 '%s', :>4 %d",url,res);
}
return CharArrayToString(result);
}
//+------------------------------------------------------------------+