Libraries: "Native" MQL HTTP Client - page 2

 

Hi!

that's a really useful idea ... and the GET part works flawlessly, but the POST part neither work for me.

My code is :

   string params[2][2];
   params[0][0] = "action";
   params[0][1] = "insert";
   params[1][0] = "status";
   params[1][1] = "test";
   string filenames[][];
   string response;
  
   HttpPOST("www.mysite.com", "/ws/form.php", params, filenames, response);
   Comment(response);

The fact is that the request don't seem to reach the server, nothing appear in the Apache log. I have been testing by code blocks, and i've found that the program returns after HttpSendRequestA call, so the request is unsuccessful. I've tried to import the GetLastError function from wininet to gather some extra information about the error, but it doesn't seem possible due the fact that there is a function with the same name in mql4.

I've also checked the contents of the _req.txt file :

-----------------------------HOFSTADTER
Content-Disposition: form-data; name="status"
test
-----------------------------HOFSTADTER
Content-Disposition: form-data; name="action"
insert
-----------------------------HOFSTADTER--

Maybe there is a problem with the generation routine of request[] ? It would be simpler if we disable the capability of upload files ? Any idea for further debugging will be appreciated.

By the way i've tested your twitpic code and neither work for me. Can then be a problem with the wininet version ?¿ I'm using Win XP.

Thanks !!!

Josep M.

 
Great job! Thank you very much.
 

Thank you very much gunzip.

Now MT4 can communicate with PHP ....

//+------------------------------------------------------------------+
//|                                                 ghttpTesting.mq4 |   
//|                           by : Giovanni (giovanni4000@gmail.com) |
//|                                                                  |
//| Thanks to "gunzip" at : http://codebase.mql4.com/7353            |
//|                                                                  |
//| 1) Put this script to ..../experts/scripts/ folder               |
//| 2) Put "ghttp.mqh" to ..../experts/include/ folder               |
//| 3) Create "ghttptesting.php", put to .../apache/htdocs/ folder   |
//| 4) Open MT4 client, activate the "DLL import", open a chart      |
//|    ex: EURUSD M15                                                |
//| 5) Attach this scripts to chart. See result in "experts tab"     |
//|    and on the chart                                              |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| file: "ghttptesting.php" example.                                |
//|                                                                  |
//| <?php                                                            |
//| $openprc = $_GET["open"];                                        |
//| $closeprc = $_GET["close"];                                      |
//| $highprc = $_GET["high"];                                        |
//| $lowprc = $_GET["low"];                                          |
//| if ($openprc < $closeprc) {                                      |
//|     echo ("Prev Candle is: BULLISH.");                           |
//| }                                                                |
//| else {                                                           |
//|     echo ("Prev Candle is: BEARISH.");                           |
//| }                                                                |
//| ?>                                                               |
//+------------------------------------------------------------------+
#include <ghttp.mqh>
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init(){
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()  {
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() {
   string response;
   bool connection;
   //---
   double dOpen,dClose,dHigh,dLow;
   int tf = Period();
    // Get prev bar data ...
   dOpen = iOpen(Symbol(),tf,1); 
   dClose = iClose(Symbol(),tf,1);
   dHigh = iHigh(Symbol(),tf,1);
   dLow = iLow(Symbol(),tf,1);
   //---  
   string query = StringConcatenate("http://localhost/ghttptesting.php?open=", dOpen ,"&close=", dClose ,"&high=", dHigh ,"&low=", dLow);
   connection = HttpGET(query, response);
   if (connection == false) {
      Comment("Error getting HttpGet ...");
      Print("Error getting HttpGet ...");
   }
   else {
      Comment("The Response => ", response);
      Print("The Response => ", response);
   }
   //---
   return(0);
}
//+------------------------------------------------------------------+
 
This no longer works in MT4 build 600, can we please get an update?
 
mql4_comments:
This no longer works in MT4 build 600, can we please get an update?
The changes required probably just involve changing A (Ansi) WinInit.dll calls to the W (Unicode) equivalent, though you may not need to use this library at all thanks to the following:

MT4 Build 600+ includes the WebRequest() function which directly supports Http Get and Post operations from within MT4 code. See WebRequest within Help or https://docs.mql4.com/common/webrequest
WebRequest - MQL4 Documentation
  • docs.mql4.com
WebRequest - MQL4 Documentation
 
autoabacusmt5:
The changes required probably just involve changing A (Ansi) WinInit.dll calls to the W (Unicode) equivalent, though you may not need to use this library at all thanks to the following:

MT4 Build 600+ includes the WebRequest() function which directly supports Http Get and Post operations from within MT4 code. See WebRequest within Help or https://docs.mql4.com/common/webrequest

  Thanks for the update autoabacusmt5. I use MT4 build 646, but  function WebRequest() is not found. And at "Tools => Option => Expert Advisor" tab, i can not put allowed URL there (no input form). Do i miss something ?


 

QuotesDemo
QuotesDemo
  • votes: 39
  • 2014.05.27
  • MetaQuotes Software Corp.
  • www.mql5.com
The Expert Advisor shows the current values of World Stock Indices from Google Finance using WebRequest function.
 

Hi autoabacusmt5,

the WebRequest works great after i upgrade my MT4 from build 646 to build 670.

Thanks

Reason: