Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 9th, 2012  |  syntax: None  |  size: 5.77 KB  |  views: 80  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdlib.mqh>
  2. #include <stderror.mqh>
  3.  
  4. //+------------------------------------------------------------------+
  5. //| DLL imports                                                      |
  6. //+------------------------------------------------------------------+
  7.  
  8. #import "wininet.dll"
  9. int InternetOpenA (
  10.    string lpszAgent,
  11.    int dwAccessType,
  12.    string lpszProxyName,
  13.    string lpszProxyBypass,
  14.    int dwFlags
  15. );
  16.  
  17. int InternetConnectA(
  18.    int hInternet,
  19.    string lpszServerName,
  20.    int nServerPort,
  21.    string lpszUsername,
  22.    string lpszPassword,
  23.    int dwService,
  24.    int dwFlags,
  25.    int dwContext
  26. );
  27.  
  28. int HttpOpenRequestA(int hConnect, string lpszVerb, string lpszObjectName, string lpszVersion,
  29.  string lpszReferer, string& lplpszAcceptTypes[], int dwFlags, int dwContext);
  30.  
  31.  
  32. bool HttpSendRequestA(int handle, string headers, int headersLen, int& optional[], int optionalLen);
  33.  
  34. bool InternetReadFile(
  35.    int hFile,
  36.    string lpBuffer,
  37.    int dwNumberOfBytesToRead,
  38.    int &lpdwNumberOfBytesRead[]
  39. );
  40.  
  41. bool InternetCloseHandle(
  42.    int hInternet
  43. );
  44.  
  45. bool HttpAddRequestHeadersA(int handle, string headers, int headersLen, int modifiers);
  46.  
  47. #define AGENT                           "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)"
  48. #define INTERNET_OPEN_TYPE_DIRECT       0
  49. #define HTTP_ADDREQ_FLAG_ADD            0x20000000
  50. #define HTTP_ADDREQ_FLAG_REPLACE        0x80000000
  51.  
  52. //InternetConnect - nServerPort
  53. #define INTERNET_DEFAULT_FTP_PORT      21
  54. #define INTERNET_DEFAULT_GOPHER_PORT   70
  55. #define INTERNET_DEFAULT_HTTP_PORT     80
  56. #define INTERNET_DEFAULT_HTTPS_PORT    443
  57. #define INTERNET_DEFAULT_SOCKS_PORT    1080
  58. #define INTERNET_INVALID_PORT_NUMBER   0
  59.  
  60. //InternetConnect - dwService
  61. #define INTERNET_SERVICE_FTP     1
  62. #define INTERNET_SERVICE_GOPHER  2
  63. #define INTERNET_SERVICE_HTTP    3
  64.  
  65. //HttpOpenRequest - dwFlags
  66. /*#define INTERNET_FLAG_CACHE_IF_NET_FAIL
  67. #define INTERNET_FLAG_HYPERLINK
  68. #define INTERNET_FLAG_IGNORE_CERT_CN_INVALID
  69. #define INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
  70. #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
  71. #define INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
  72. #define INTERNET_FLAG_KEEP_CONNECTION
  73. #define INTERNET_FLAG_NEED_FILE
  74. #define INTERNET_FLAG_NO_AUTH
  75. #define INTERNET_FLAG_NO_AUTO_REDIRECT*/
  76. #define INTERNET_FLAG_NO_CACHE_WRITE            0x04000000
  77. /*#define INTERNET_FLAG_NO_COOKIES
  78. #define INTERNET_FLAG_NO_UI*/
  79. #define INTERNET_FLAG_PRAGMA_NOCACHE            0x00000100
  80. #define INTERNET_FLAG_RELOAD                    0x80000000
  81. /*#define INTERNET_FLAG_RESYNCHRONIZE
  82. #define INTERNET_FLAG_SECURE*/
  83.  
  84. #define INTERNET_FLAG_NO_UI             0x00000200
  85.  
  86.  
  87. int start()
  88.   {
  89.    //string URL = "www.ronaldraygunforex.com/cloud/test.php";  
  90.    wPost();  
  91. }
  92.  
  93.    
  94. int init()
  95. {
  96.  
  97. }
  98.  
  99. int deinit()
  100. {
  101. }
  102.  
  103. string wPost(){
  104.      
  105.    int hInternetOpen = InternetOpenA (AGENT,0,"0","0",0);
  106.    Print("hInternetOpen: ", hInternetOpen);
  107.    
  108.    //int hInternetConnect = InternetConnectA(hInternetOpen, "www.ronaldraygunforex.com", INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);
  109.    int hInternetConnect = InternetConnectA(hInternetOpen, "www.ronaldraygunforex.com", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL);
  110.    Print("hInternetConnect: ", hInternetConnect);
  111.    
  112.    string postdata = "input=test" ;
  113.      
  114.    int dwOpenRequestFlags =   // _IGNORE_REDIRECT_TO_HTTP |
  115.                              // _IGNORE_REDIRECT_TO_HTTPS |
  116.                              // INTERNET_FLAG_KEEP_CONNECTION |
  117.                              // INTERNET_FLAG_NO_AUTO_REDIRECT |
  118.                              // INTERNET_FLAG_NO_COOKIES |
  119.                              // INTERNET_FLAG_NO_CACHE_WRITE |
  120.                              INTERNET_FLAG_NO_UI |
  121.                              INTERNET_FLAG_RELOAD;
  122.  
  123.    string accept[] = {"Accept: text/*\r\n"};
  124.  
  125.    //int hHttpOpenRequest = HttpOpenRequestA(hInternetConnect, "POST", "cloud/test.php", "HTTP/1.1", NULL, accept,
  126.    //           INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD , 0);
  127.    int hHttpOpenRequest = HttpOpenRequestA(hInternetConnect, "POST", "cloud/test.php", "HTTP/1.1", NULL, accept,
  128.               dwOpenRequestFlags, NULL);
  129.              
  130.    Print("hHttpOpenRequest: ", hHttpOpenRequest);  
  131.  
  132.    int request[];
  133.    int i     = 0,
  134.       idx   = 0,
  135.       r     = 0,
  136.       len   = 0
  137.    ;
  138.  
  139.  
  140.    len = StringLen(postdata);
  141.    int theCharArray[];
  142.    ArrayResize(theCharArray, len);
  143.    for(int k=0;k<len;k++) {
  144.       string c = StringSubstr(postdata,k,1);
  145.       int  asc = StringGetChar(c, 0);
  146.       theCharArray[k] = asc;
  147.    }
  148.    
  149.    ArrayResize(request, len);
  150.    ArrayInitialize(request, 0);
  151.  
  152.    //Print("len " + len);
  153.    
  154.    for (i = 0; i < len; i++) {
  155.       //int charValue = FileReadInteger(_req, CHAR_VALUE);
  156.       int charValue = theCharArray[i];
  157.       //Print("charValue["+i+ "] " + charValue );
  158.       request[r] |= charValue << (idx * 8);
  159.       idx = (idx + 1) %4;
  160.       if (idx == 0) {
  161.          r++;
  162.       }
  163.       //Print("request["+r+"] " + request[r]);
  164.    }
  165.    
  166.    bool bHttpSendRequestA = HttpSendRequestA(hHttpOpenRequest, "Content-type: application/x-www-form-urlencoded", -1, request, len );
  167.    Print("bHttpSendRequestA: ", bHttpSendRequestA);
  168.    
  169.    string mContent = "";
  170.    int lpdwNumberOfBytesRead[1];
  171.    string sResult;
  172.    while (InternetReadFile(hHttpOpenRequest, mContent, 255, lpdwNumberOfBytesRead) != FALSE) {
  173.         if (lpdwNumberOfBytesRead[0] == 0) break;
  174.         sResult = StringConcatenate(sResult , StringSubstr(mContent, 0, lpdwNumberOfBytesRead[0]));
  175.    }
  176.    
  177.    Print("sResult: ", sResult);
  178.    
  179.    InternetCloseHandle(hHttpOpenRequest);
  180.    InternetCloseHandle(hInternetOpen);
  181.    InternetCloseHandle(hInternetConnect);
  182.  
  183. }