Download MetaTrader 5

Help with HTTP Post

To add comments, please log in or register
Richard Read
Richard Read  


Hoping someone can help me with this. I'm trying to send an HTTP Post with parameters, but have not used them much. How do I format/send the parameters? Where do the parameters go?

Here is my basic code so far:

void OnStart()
   string headers = "Content-Type: application/x-www-form-urlencoded";
   string data = "";
   string acceptTypes[1] = {"*/*"};

   int HttpOpen = InternetOpenW("",1, "", "", 0);  
   int HttpConnect = InternetConnectW(HttpOpen, url, 7777, "", "", 3, 0, 1);
   int HttpRequest = HttpOpenRequestW(HttpConnect, "POST", "/index.php", "HTTP/1.1", "", acceptTypes, 0, 1);
   bool result = HttpSendRequestW(HttpRequest, headers, StringLen(headers), data, StringLen(data));

   if (HttpOpen > 0)
   if (HttpRequest > 0)

And these are the parameter fields:

//authentication header to enable the sending and receiving of HTTP requests. 
//Please use the below credentials if you intend to update, create or delete indicator posts/data sets!
//Basic GET queries do not require authentication, but if you want to do any kind of editing or updating of meta data you will need to use the below,
//otherwise REST will simply throw a 404 error
$headers = array (
        'Authorization' => 'Basic ' . base64_encode( 'Werner' . ':' . 'CAwU keBK ZwGL mU54 YRKv KZAn' ),

//prepare body of request with meta key/value for inserting or updating new dataset
//technically you do not need to have such an array for GET requests or DELETE requests (you only need the data set ID for those)
//, only if you wish to update or add/insert a new data set into the database
//Also make sure to add 'status' => 'publish' to the array of data below to ensure that you dataset is published(queryable)
$body = array (
    'title'                     =>      $currencyPair,
    'indicator_currency_pair'   =>      $currencyPair,
    'indicator_time'            =>      $indicatorTime,
    'indicator_alpha_n'         =>      $alphaN,
    'indicator_value_2'         =>      $value2,
    'indicator_value_3'         =>      $value3,
    'indicator_value_4'         =>      $value4

//make POST request, i.e. update/add/delete post meta/data set as per $method variable defined earlier on
$response = wp_remote_request ($url, array(
    'method'    =>      $method,
    'headers'   =>      $headers,
    'body'      =>      $body

Would really appreciate any help with this!

To add comments, please log in or register