I posted this in the .NET forum but thought here might be a better option.
I am currently trying to use the new API and am trying to get my C# code to retrieve the session token. I have verified that I have uploaded the correct certificate to Betfair by running both the curl and python samples and they return the correct session token.
I have been scouring the web and everyone says the method below is how to send a client certificate through an HTTP POST. I have replaced all sensitive data with XXXXX. When I execute the code, i get the JSON returned {"loginStatus":"CERT_AUTH_REQUIRED"}
I would appreciate it if someone could give me some direction on this one, as I cannot find any sample c# code for this part of the application on the betfair site, only java and python.
const string host = "https://identitysso-api.betfair.com/api/certlogin";
X509Certificate2 certificate = new X509Certificate2(@"client-2048.p12", "XXXXXX", X509KeyStorageFlags.PersistKeySet);
ServicePointManager.ServerCertificateValidationCal lback += ServerCertificateValidationCallback;
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(host);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("X-Application", "XXXXXXXXXXXXXX");
StringBuilder postData = new StringBuilder();
postData.Append(String.Format("username={0}&", "XXXXXXXXXX"));
postData.Append(String.Format("password={0}", "XXXXXXXXXXX"));
Console.WriteLine("Post Data: " + postData.ToString());
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] postBytes = ascii.GetBytes(postData.ToString());
req.ContentLength = postBytes.Length;
Stream postStream = req.GetRequestStream();
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Flush();
postStream.Close();
req.ClientCertificates.Add(certificate);
WebResponse resp = null;
try
{
resp = req.GetResponse();
}
catch (Exception ex)
{
}
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
string result = sr.ReadToEnd();
Console.WriteLine(result);
return result;
I am currently trying to use the new API and am trying to get my C# code to retrieve the session token. I have verified that I have uploaded the correct certificate to Betfair by running both the curl and python samples and they return the correct session token.
I have been scouring the web and everyone says the method below is how to send a client certificate through an HTTP POST. I have replaced all sensitive data with XXXXX. When I execute the code, i get the JSON returned {"loginStatus":"CERT_AUTH_REQUIRED"}
I would appreciate it if someone could give me some direction on this one, as I cannot find any sample c# code for this part of the application on the betfair site, only java and python.
const string host = "https://identitysso-api.betfair.com/api/certlogin";
X509Certificate2 certificate = new X509Certificate2(@"client-2048.p12", "XXXXXX", X509KeyStorageFlags.PersistKeySet);
ServicePointManager.ServerCertificateValidationCal lback += ServerCertificateValidationCallback;
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(host);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("X-Application", "XXXXXXXXXXXXXX");
StringBuilder postData = new StringBuilder();
postData.Append(String.Format("username={0}&", "XXXXXXXXXX"));
postData.Append(String.Format("password={0}", "XXXXXXXXXXX"));
Console.WriteLine("Post Data: " + postData.ToString());
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] postBytes = ascii.GetBytes(postData.ToString());
req.ContentLength = postBytes.Length;
Stream postStream = req.GetRequestStream();
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Flush();
postStream.Close();
req.ClientCertificates.Add(certificate);
WebResponse resp = null;
try
{
resp = req.GetResponse();
}
catch (Exception ex)
{
}
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream, Encoding.UTF8);
string result = sr.ReadToEnd();
Console.WriteLine(result);
return result;


Comment