title: Dart https request with ssl certificate please
body: <p>I have the following Javascript code which works fine when I run it with nodejs. However, I would like to write something similar that works with Dart. I've gone through the Dart documentation and cannot find any examples. I would be very grateful if someone could show me how to rewrite the following using Google Dart please. Many thanks in advance!</p>
  
  <pre class="lang-js prettyprint-override"><code>var https = require('https');
  var fs = require('fs');
  var url = require('url');
  
  var uri = "https://identitysso-api.betfair.com:443/api/certlogin";
  var data = 'username=xxxxxxxx&amp;password=xxxxxxxx';
  var appKey = 'xxxxxxxxxxxxxx'
  
  var options = url.parse(uri);
  options.method = 'POST';
  options.headers = {
      'Content-Type': 'application/x-www-form-urlencoded',
      'X-Application': appKey
  };
  options.key = fs.readFileSync('client-2048.key');
  options.cert = fs.readFileSync('client-2048.crt');
  options.agent = new https.Agent(options);
  
  var req = https.request(options, function(res) {
      console.log("statusCode:", res.statusCode);
      var responseData = "";
      res.on('data', function(d) {
          responseData += d;
      });
      res.on('end', function() {
          var response = JSON.parse(responseData);
          console.log("sessionToken:", response.sessionToken.replace(/\d/g, ''));
      });
      res.on('error', function(e) {
          console.error(e);
      });
  });
  
  req.end(data);
  </code></pre>
  
  <p>I've got as far as the following:-</p>
  
  <pre class="lang-dart prettyprint-override"><code>import 'dart:io';
  
  void main() {
      var uri = "https://identitysso-api.betfair.com:443/api/certlogin";
      var data = 'username=xxxxxxxx&amp;password=xxxxxxxx';
      var appKey = 'xxxxxxxxxxxx';
      var method = 'POST';
  
      HttpClient client = new HttpClient();
      client.openUrl(method,Uri.parse(uri))
      .then((HttpClientRequest request) {
          request.headers.set(HttpHeaders.CONTENT_TYPE, 'application/x-www-form-urlencoded');
          request.headers.set('X-Application', appKey);
          request.write(data);
          return request.close();
       })
       .then((HttpClientResponse response) {
      // Process the response.
       });
  }
  </code></pre>
  
  <p>But can not find anything in the docs where it tells you how to add a certificate to HttpClient or HttpRequest?? Any help gratefully received many thanks in advance.</p>