UPDATE 9 March 2017: I added a bounty to this question, I think it is a hard and challenging problem and can prove that Mathematica is capable of almost anything.
Sadly user1473011's answer does not work. I came back to this issue for many times, so far all my attempts to handle this from within Mathematica failed. Although I have a working solution in the form of a Java program I would rather have it done inside Mathematica.
With Mathematica 11.0.1 on Windows 10 I want to use URLFetch to do a so called 'Non-interactive/Bot login' at Betfair. The Betfair API manual gives this example in Python:
#!/usr/bin/env python
import requests
payload = 'username=myusername&password=password'
headers = {'X-Application': 'SomeKey', 'Content-Type': 'application/x-www-form-urlencoded'}
resp = requests.post('https://identitysso.betfair.com/api/certlogin', data=payload, cert=('client-2048.crt', 'client-2048.key'), headers=headers)
if resp.status_code == 200:
resp_json = resp.json()
print resp_json['loginStatus']
print resp_json['sessionToken']
else:
print "Request failed."
'client-2048.crt' and 'client-2048.key' are files which I have generated with win-openssl and are stored on disk. I have a username and password.
There are also examples for C# and Java in the API Manual
I came as far the following URLFetch but I get a HTTP 405 return code, which was to be expected because I did not know how to handle the certification file, I generated earlier, basically the question is how to translate the python to URLfetch with an emphasis on the cert file.
URLFetch["https://identitysso.betfair.com/api/certlogin", {"StatusCode", "Headers", "Content"}, "Headers" -> {"X-Application" -> "nilostep", "Accept" ->"application/json"}, "Parameters" -> {"Username" -> "myusername", "Password" -> "mypassword"}];
I have successfully used the API before but I copied a 'session token' for access which you can get only after manually logging in. Related question: How to access a web API with HTTP POST and JSON
(EDIT: Any example of a https secure login using certification keys using Mathematica will help.)
(EDIT-2: Might this help?: Can anyone explain how to use Mathematica's OAuth package? ? )
URLFetch[" http
. $\endgroup$