I'm trying to send a POST request to IG's REST API to log in and retrieve a token for trading. The required format of the request is

Quote:
Request Section Details
Action POST https://demo-api.ig.com/gateway/deal/session
Header Content-Type: application/json; charset=UTF-8
Accept: application/json; charset=UTF-8
VERSION: 2
X-IG-API-KEY: 5FA056D2706634F2B7C6FC66FE17517B
Body
{
"identifier": "A12345",
"password": "112233"
}


I already have a functioning MQL4 code that accomplishes this, but now I've tried to adapt it to Zorro and can't get it to work. Here is the relevant poriton of the Zorro script. The first part is mine and the part with the codnitionals just taken from the example in the manual.

(Please note escape characters aren't appearing the in the quotations, e.g. bodystring is actually ""{BACKSLASH"identifierBACKSLASH" etc.)

Quote:
char inputbody[100];
char content[1000];
string url = "https://demo-api.ig.com/gateway/deal/session";
string bodystring = "{"identifier": "luke1234", "password": "One23456."}";
strcpy (inputbody, bodystring);
string inputheader = "Content-Type: application/json; charset=UTF-8 rn Accept: application/json; charset=UTF-8 rn X-IG-API-KEY: 6ee4e97eca7d1dc5afa51a8f8028f3cff725bb27";

int id = http_send (url, inputbody, inputheader);

while(!http_status(id)) {
if(!wait(100)) return; // wait for the server to reply
printf(".");
}
if(http_status(id) > 0) { //transfer successful?
http_result(id,content,1000); //get the replied IP
printf("n%s",content);

}
else
printf("nError during transfer!");

http_free(id);


The API key etc. are all correct, as these work in Metatrader 4. But printf is producing the following:

Quote:
<!--[if IE 7]><html class="ie7 nojs" lang=""> <![endif]-->
<!--[if IE 8]><html class="ie8 nojs" lang=""> <![endif]-->
<!--[if IE 9]><html class="ie9 nojs" lang=""> <![endif]-->
<html class="gtie9" lang=""><!--<![endif]-->
<head>
<title>403</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1; requiresActiveX=true">
<meta property="og:title" content="403 Access forbidden!">
<meta property="og:url" c
<meta itemprop="url" content="/error/403">
<meta property="og:description" content="Access forbidden!">
<meta property="og:image" content="/error/include/og_image.jpg">
<meta name="keywords" content="">
<meta name="locale" id="locale" content="en_GB">
<meta name="softid" id="softid" content="igcom">
<meta name="apple-itunes-app" content="app-id=469403477">
<link rel="stylesheet" href="/error/include/errorpage.css" type="text/


Any idea what's wrong? Is this something to do with the JSON format the body of the POST request? Is there anyw ay to do this?

The MQL4 code is pretty straightforward:

Quote:

string responseheader;
char responsebody[];

string inputheader = "Content-Type: application/json; charset=UTF-8 rn Accept: application/json; charset=UTF-8 rn X-IG-API-KEY: 6ee4e97eca7d1dc5afa51a8f8028f3cff725bb27";
string bodystring = "{"identifier": "luke1234", "password": "One23456"}";

char inputbody[];
StringToCharArray(bodystring, inputbody);

string url = "https://demo-api.ig.com/gateway/deal/session";

int request = WebRequest("POST", url, inputheader, 50, inputbody, responsebody, responseheader);

Last edited by MaskOfZorro; 06/06/17 09:58.