Forex



Go Back   Forex Trading > Downloads > Tools and utilities
Forex Forum Register More recent Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 06-03-2007, 07:42 PM
bamdad's Avatar
Junior Member
 
Join Date: Jan 2006
Posts: 7
bamdad is on a distinguished road
Send HTTP-Post Request With Meta

Hi Guys
I'm Trying To Send HTTP-Post request with metatrader.
i tried to write a dll for this action but it doesn't..
when i call the request(); function in dll, the Script/Indicator Will stop working...
here is the source code

PHP Code:
// pasargad.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "pasargad.h"

#define WIN_OS
#define _DEBUG_PRINT(X)   /* X */

#include <iostream>
#include <string>
#include <stdlib.h>
#include <assert.h>

#include <Winsock2.h>
#pragma comment( lib, "wsock32.lib" )

#define SEND_RQ(MSG) \
  
send(sock,MSG,strlen(MSG),0);

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define MT4_EXPFUNC __declspec(dllexport)

//
//    Note!
//
//        If this DLL is dynamically linked against the MFC
//        DLLs, any functions exported from this DLL which
//        call into MFC must have the AFX_MANAGE_STATE macro
//        added at the very beginning of the function.
//
//        For example:
//
//        extern "C" BOOL PASCAL EXPORT ExportedFunction()
//        {
//            AFX_MANAGE_STATE(AfxGetStaticModuleState());
//            // normal function body here
//        }
//
//        It is very important that this macro appear in each
//        function, prior to any calls into MFC.  This means that
//        it must appear as the first statement within the 
//        function, even before any object variable declarations
//        as their constructors may generate calls into the MFC
//        DLL.
//
//        Please see MFC Technical Notes 33 and 58 for additional
//        details.
//

/////////////////////////////////////////////////////////////////////////////
// CPasargadApp

BEGIN_MESSAGE_MAP(CPasargadAppCWinApp)
    
//{{AFX_MSG_MAP(CPasargadApp)
        // NOTE - the ClassWizard will add and remove mapping macros here.
        //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPasargadApp construction

CPasargadApp::CPasargadApp()
{
    
// TODO: add construction code here,
    // Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CPasargadApp object

CPasargadApp theApp;

using namespace std;
MT4_EXPFUNC int request (charhostnamecharapicharparametersstringmessage)
{
    
WSADATA    WsaData;
    
WSAStartup (0x0101, &WsaData);

    
sockaddr_in       sin;
    
int sock socket (AF_INETSOCK_STREAM0);
    if (
sock == -1) {
        return -
100;
    }
    
sin.sin_family AF_INET;
    
sin.sin_port htons( (unsigned short)80);

    
struct hostent host_addr gethostbyname(hostname);
    if(
host_addr==NULL) {
      
_DEBUG_PRINTcout<<"Unable to locate host"<<endl );
      return -
103;
    }
    
sin.sin_addr.s_addr = *((int*)*host_addr->h_addr_list) ;
    
_DEBUG_PRINTcout<<"Port :"<<sin.sin_port<<", Address : "<< sin.sin_addr.s_addr<<endl);

    if( 
connect (sock,(const struct sockaddr *)&sinsizeof(sockaddr_in) ) == -) {
     
_DEBUG_PRINTcout<<"connect failed"<<endl ) ;
     return -
101;
    }

 
string send_str;

 
SEND_RQ("POST ");
 
SEND_RQ(api);
 
SEND_RQ(" HTTP/1.0\r\n");
 
SEND_RQ("Accept: */*\r\n");
 
SEND_RQ("User-Agent: Mozilla/4.0\r\n");

 
char content_header[100];
 
sprintf(content_header,"Content-Length: %d\r\n",strlen(parameters));
 
SEND_RQ(content_header);
 
SEND_RQ("Accept-Language: en-us\r\n");
 
SEND_RQ("Accept-Encoding: gzip, deflate\r\n");
 
SEND_RQ("Host: ");
 
SEND_RQ("hostname");
 
SEND_RQ("\r\n");
 
SEND_RQ("Content-Type: application/x-www-form-urlencoded\r\n");
 
 
//If you need to send a basic authorization
 //string Auth        = "username:password";
 //Figureout a way to encode test into base64 !
 //string AuthInfo    = base64_encode(reinterpret_cast<const unsigned char*>(Auth.c_str()),Auth.length());
 //string sPassReq    = "Authorization: Basic " + AuthInfo;
 //SEND_RQ(sPassReq.c_str());

 
SEND_RQ("\r\n");
 
SEND_RQ("\r\n");
 
SEND_RQ(parameters);
 
SEND_RQ("\r\n");

 
_DEBUG_PRINT(cout<<"####HEADER####"<<endl);
 
char c1[1];
 
int l,line_length;
 
bool loop true;
 
bool bHeader false;

 while(
loop) {
   
recv(sockc110);
   if(
l<0loop false;
   if(
c1[0]=='\n') {
       if(
line_length == 0loop false;

       
line_length 0;
       if(
message.find("200") != string::npos)
           
bHeader true;

   }
   else if(
c1[0]!='\r'line_length++;
   
_DEBUG_PRINTcout<<c1[0]);
   
message += c1[0];
 }

 
message="";
 if(
bHeader) {

     
_DEBUG_PRINTcout<<"####BODY####"<<endl) ;
     
char p[1024];
     while((
recv(sock,p,1023,0)) > 0)  {
         
_DEBUG_PRINTcout.write(p,l)) ;
         
p[l] = '\0';
         
message += p;
     }

     
_DEBUG_PRINTcout << message.c_str());
 } else {
     return -
102;
 }

 
WSACleanup( );

 return 
0;
}

MT4_EXPFUNC int __stdcall Bamdad(int aint b) {
    return 
a+b;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 06-04-2007, 09:59 AM
bamdad's Avatar
Junior Member
 
Join Date: Jan 2006
Posts: 7
bamdad is on a distinguished road
AnyOne..?

Anyone can Help ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 06-05-2007, 10:56 AM
bamdad's Avatar
Junior Member
 
Join Date: Jan 2006
Posts: 7
bamdad is on a distinguished road
one of my friends suggested me to use cURL Library ..
i try to but i couldn't i think i have to write a DLL using cURL to send request with a single function and just use that function in meta ...
any suggestion?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 06-25-2008, 03:03 PM
Senior Member
 
Join Date: Dec 2006
Posts: 111
dwmcqueen is on a distinguished road
I just noticed this - you looking for help on this? I have done this with the cURL library.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 06-25-2008, 04:50 PM
Mistigri's Avatar
Member
 
Join Date: Mar 2006
Posts: 34
Mistigri is on a distinguished road
Here is what i use ( Visual Studio 2008 - C++ DLL )

PHP Code:
Code:
//---- You need to add these includes at the top of your code
//---- #include <wininet.h>
//---- #include <atlstr.h>

MT4_EXPFUNC int __stdcall Sampleint Whatever )
{
    
//---- Declare Return Value
   
CHAR buffer[2048] ;
   
CString m_strContents;
   
DWORD dwRead;

   
/* Connect to the internet */
   
HINTERNET hiNet InternetOpen(
                            
L"InetURL/1.0",
                            
INTERNET_OPEN_TYPE_PRECONFIG,
                            
NULL,
                            
NULL,
                            
0
                           
);
   
/* if connection fails throw error */
   
if( !hiNet ) { return( -1010 ); }
   
   
/* Connect to a site */
   
HINTERNET hConnection InternetConnect(
                                    
hiNet,
                                    
L"www.yoursite.com",
                                    
INTERNET_DEFAULT_HTTP_PORT,
                                    
NULL,
                                    
NULL,
                                    
INTERNET_SERVICE_HTTP,
                                    
0,
                                    
0
                                   
);
   
/* if connetion to site failed */
   
if( !hConnection )
   {
      
InternetCloseHandle(hiNet);
      return( -
1020 );
   } 
// COULD NOT CONNECT TO WEBSITE

/* Get Data */
   
HINTERNET hData HttpOpenRequesthConnectionL"GET"L"/yourpage.php"NULLNULLNULLINTERNET_FLAG_KEEP_CONNECTION);
   if ( !
hData )
   {
      
InternetCloseHandle(hConnection);
      
InternetCloseHandle(hiNet);
      return( -
1030 );                                      // PAGE NOT FOUND
   
}

   
HttpSendRequesthDataNULL0NULL0);
   
bool Done false;
   while( !
Done )
   {
         
InternetReadFilehDatabuffer255, &dwRead );
         if ( 
dwRead == )  {  Done true; }
         
buffer[dwRead] = 0;
         
m_strContents += buffer;
   }

   
//---- Here you can output m_strContents
        
MessageBox0m_strContentsL"WebPage OutPut");

         
InternetCloseHandle(hConnection);
         
InternetCloseHandle(hiNet);
         
InternetCloseHandle(hData);

You could use post instead of get and pass variables in your url ...
PHP Code:
/* Post Data */
   
HINTERNET hData HttpOpenRequesthConnectionL"POST"L"/yourpage.php?var1=value1&var2=value2 etc ... "NULLNULLNULLINTERNET_FLAG_KEEP_CONNECTION); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 06-25-2008, 06:56 PM
Kalenzo's Avatar
Senior Member
 
Join Date: Dec 2005
Location: Bydgoszcz - Poland
Posts: 724
Kalenzo is on a distinguished road
Guys, there is much more simple way, you can write your request to file, then throw alert - and in metatrader properties - event tab - choose instead of wav file - your bat file, then construct bat file in the way that will read the requrest from txt file.
Simple and works allways - without any DLL's
__________________
You need proffesional mql coder? Contact me! I will help you!
........................................
http://www.fxservice.eu/
........................................
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 03-05-2009, 12:37 PM
Senior Member
 
Join Date: Oct 2007
Posts: 117
mudar is on a distinguished road
Thanks, very useful,

just two question
1. <wininet.h> and <atlstr.h> are the one I am getting on Google or should I search them somewhere else ?

2. What if I need to receive a response from my request ?

Thanks a lot !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
MT4_EXPFUNC


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Send Mail cardio Setup Questions 7 10-23-2006 04:51 AM
Send Order problem intelligent_14 Questions 0 08-03-2006 11:37 AM
Script to Send Emails babarmughal Expert Advisors - Metatrader 4 7 05-16-2006 03:27 AM


All times are GMT. The time now is 02:38 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.