Teach how to hash data in mql4 - page 4

 
Reshetov:

Actually, both in GET and POST requests everything is passed in the form: id=value, i.e. parameter name and value through equal sign. In addition, all characters that are not Latin letters and numbers are coded with % (character code).

There's something wrong there, I'm trying to figure it out, but it doesn't work:

  if (!HttpSendRequestA(hReq, NULL, 0, request, len))
  {
    return (false);
  }
 

I am probably boring the topicstatter with my researches, if you tell me, I will go to a monastery

ZS: Eventually, the code will work on bits

 
Thank you
 
sanyooooook:

Are you asking me?

See example: https://www.mql5.com/ru/articles/276
//------------------------------------------------------------------ SendData
bool SendData(string file, string mode)
{
  string smb=Symbol();
  string Head="Content-Type: application/x-www-form-urlencoded"; // заголовок
  string Path="/mt5swap/metaswap.php"; // путь к странице
  string Data="server="+AccountInfoString(ACCOUNT_SERVER)+
              "&pair="+smb+
              "&long="+DTS(SymbolInfoDouble(smb, SYMBOL_SWAP_LONG))+
              "&short="+DTS(SymbolInfoDouble(smb, SYMBOL_SWAP_SHORT));

  tagRequest req; // инициализация параметров
  if (mode=="GET")  req.Init(mode, Path+"?"+Data, Head, "",   false, file, true);
  if (mode=="POST") req.Init(mode, Path,          Head, Data, false, file, true);

  return(INet.Request(req)); // посылаем запрос на сервер
}
 

even that doesn't work:

#import "wininet.dll"
        int InternetAttemptConnect(int x);
  int InternetOpenA(string sAgent, int lAccessType, string sProxyName="", string sProxyBypass="", int lFlags = 0);
        int InternetConnectA(int hInternet, string lpszServerName, /*WORD*/ int nServerPort, string lpszUsername, string lpszPassword, int dwService, int dwFlags,  int dwContext);
  int HttpOpenRequestA(int hConnect, string lpszVerb, string lpszObjectName, string lpszVersion, string lpszReferer, string lplpszAcceptTypes, int dwFlags, int dwContext);
  int HttpSendRequestA(int hRequest, string lpszHeaders, int dwHeadersLength, int& lpOptional[], int dwOptionalLength);
  int InternetCloseHandle(int hInet);
#import

#define  INTERNET_OPEN_TYPE_PRECONFIG  0   // use registry configuration
#define  INTERNET_FLAG_KEEP_CONNECTION   0x00400000  // use keep-alive semantics
#define  INTERNET_SERVICE_HTTP   3

//+------------------------------------------------------------------+
int start()
{
        string Host="https://secure.indx.ru";
        string Path="https://secure.indx.ru/api/v1/tradejson.asmx";
        
        // читаем данные 
        int h=FileOpen("text.txt", FILE_BIN|FILE_READ); if (h<0) return;
        FileSeek(h, 0, SEEK_SET);       int size=MathFloor(FileSize(h)/4);
        int data[], i=0;        ArrayResize(data, size); // изменили размер
        while (!FileIsEnding(h)) { data[i]=FileReadInteger(h, LONG_VALUE); i++; }
        FileClose(h); // 
        // выводим прочитанный массив для проверки
        string st="";
        for (i=0; i<size; i++) 
        {
                st=st+CharToStr(data[i]&255); st=st+CharToStr(data[i]>>8&255); 
                st=st+CharToStr(data[i]>>16&255); st=st+CharToStr(data[i]>>24&255); 
        }
        Print("Размер файла: "+size*4+"  байт");
        Print("Данные: "+st);
        
        int hInternetSession, hConnectHandle, hResourceHandle, result;
        if(InternetAttemptConnect(0)!=0) { Print("error InternetAttemptConnect"); return(0); }
        hInternetSession=InternetOpenA("Microsoft Internet Explorer",  INTERNET_OPEN_TYPE_PRECONFIG, "", "", 0); 
        if (hInternetSession<=0) { Print("error InternetOpenA()"); return(0); }
        
        hConnectHandle=InternetConnectA(hInternetSession, Host, 80, "", "", INTERNET_SERVICE_HTTP, 0, 0); 
        if (hConnectHandle<=0) { Print("error InternetConnect()"); return(0); }
        
        hResourceHandle=HttpOpenRequestA(hConnectHandle, "POST", Path, "", "", "", INTERNET_FLAG_KEEP_CONNECTION, 0); 
        if (hResourceHandle<=0) { Print("error HttpOpenRequest()"); return(0); }
        
        result=HttpSendRequestA(hResourceHandle, "Content-Type: application/x-www-form-urlencoded", 47, data, size);
        Print(result);
        if (result<=0) { Print("error HttpSendRequestA()"); return(0); }
        
        InternetCloseHandle(hResourceHandle);
        InternetCloseHandle(hConnectHandle);
        InternetCloseHandle(hInternetSession);
}
//+------------------------------------------------------------------+
 

I don't think json will work here either.

ran it with default parameters, it doesn't work, error on post function

HttpSendRequestwW
 
and I think the problem is with this function, judging by the comments , I'm not the only one who can't get it to work
 
sanyooooook:
and it seems to me that the problem is with this function, judging by the comments , I'm not the only one who can't get it to work
https://www.mql5.com/ru/articles/276
 

I looked at the article, it sends something like: server=Metaquotes&pair=EURUSD&bid=1.4512&time=13286794

I need to send it in json format. As far as I understood all the same but instead of red string it is this with its own parameters: {"Login":"","Wmid":"","Culture":"","Signature":""}

If sending would go, at least I would get a message that request is invalid, but instead I get silence.

 
sanyooooook:

I looked at the article, it sends something like: server=Metaquotes&pair=EURUSD&bid=1.4512&time=13286794

I need to send it in json format. As far as I understood all the same but instead of red string it is this with its own parameters: {"Login":"","Wmid":"","Culture":"","Signature":""}

well, yeah. i hope you do not confuse the sending method (POST) and its data format (json in your case).

If sending would go, at least I would get a shibboleth that the request is not correct, but in place of this silence.

Sasha, put yourself some kind of Charles, why do you suffer so much :)

Reason: