Libraries: Http Client - page 2

 

Samples

mql (Expert/Indicator)

#include <http51.mqh>
int    httpStatus[1];
string httpParams [0,2];
int start()  {
   ArrayResize(httpParams, 0);
   // calculate signal
   string signal = "Sell";
   string account = "" + AccountNumber();
   
   addParam("symbol" ,Symbol(), httpParams);
   addParam("signal" ,signal,   httpParams);
   addParam("account",account,  httpParams);
   string toServer = ArrayEncode(httpParams);
   string fromServer = httpPOST("http://127.0.0.1:80/Test.jsp", toServer, httpStatus);
   if (httpStatus[0]==200) {
      //Simple parse string from server :)
      Alert(fromServer);
   } else {
      //Error catching :(
      if (httpStatus[0]>0) {
         Alert("Http Error ",httpStatus[0]," Description:", fromServer);
      } 
      if (httpStatus[0]<0) {
         Alert("Dll/INet/System Error ",httpStatus[0]," Description:", fromServer);
      } 
   }
   
   return(0);
}

Test.jsp

<%@ page import="java.util.*;" %><%
    String account = request.getParameter("account");
    String symbol  = request.getParameter("symbol");
    String signal   = request.getParameter("signal");
    //....
    String result =  (new Date()) + " Signal:" + signal;
%><%=result%>
 
string URLEncode(string toCode) {
  int max = StringLen(toCode);
  string RetStr = "";
  for(int i=0;i<max;i++) {
    string c = StringSubstr(toCode,i,1);
    int  asc = StringGetChar(c, 0);
    if((asc == 95) || (asc == 46) || (asc > 47 && asc < 58) || (asc > 64 && asc < 91) || (asc > 96 && asc < 123)) 
      RetStr = StringConcatenate(RetStr,c);
    else if (asc == 32)
      RetStr = StringConcatenate(RetStr,"+");
    else {
      RetStr = StringConcatenate(RetStr,"%",hex(asc));
    }
  }
  return (RetStr);
}


I add the asc == 95 case in order to keep my underscores underscores and 46 in order to keep my points too...

 
Great job! Thanks!
 

After I compile the script, http51.mqh, I got this error: HTTP:-1 Error: Can't send request

Can anybody tell me what the problem is? Thanks

 
Hello, is there a way how to post whole (.ex4) file?
 
Is it possible to upload the files with that library as well?
 
Oh right! Thank you very very much. I have a question... what happens if the client happens not to have the DLL in its system???
 

Hi to all,

Can someone tell me how to use basic HTTP authentication using this library?

I know that the underlaying library is WinHTTP which supports basic authentication but I can't manage to get it working inside script.

Thank you so much!

 

Hi.What's this argument in the functions?what's used for?

int  status []
 

Hi,

Is it possible to get access to the source code for the http51.dll? 

Reason: