Non interactive login

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmsrptd
    Junior Member
    • Jul 2013
    • 2

    #1

    Non interactive login

    Hi,

    can anyone share the webrequest construction to post on https://identitysso.betfair.com/api/certlogin?
    I could follow this https://api.developer.betfair.com/se...28bot%29+login until after the curl test (OK) but when I send the request through C# I'm always getting the bad request (400) error.

    Here's what I got:

    public static LoginResponse Login()
    {
    HttpWebRequest request = null;
    ServicePointManager.Expect100Continue = false;

    //ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
    X509Certificate cert = X509Certificate.CreateFromCertFile(Definitions.CER TIFICATE_FOLDER + "client-2048.pem");
    request = (HttpWebRequest)WebRequest.Create(new Uri("https://identitysso.betfair.com/api/certlogin"));
    request.KeepAlive = false;
    //request.ProtocolVersion = HttpVersion.Version10;
    request.ClientCertificates.Add(cert);
    //request.UserAgent = null;
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    //request.Headers.Add(HttpRequestHeader.AcceptCharse t, "ISO-8859-1,utf-8");
    request.Headers.Add("X-Application", Definitions.APPKEY);
    string postData = "body=username=" + Definitions.USERNAME + "&password=" + Definitions.PASSWORD;
    ASCIIEncoding encoding = new ASCIIEncoding();
    byte[] byte1 = encoding.GetBytes(postData);
    request.ContentLength = byte1.Length;
    Stream newStream = request.GetRequestStream();
    newStream.Write(byte1, 0, byte1.Length);
    newStream.Close();

    try
    {
    using (WebResponse response = request.GetResponse())
    using (Stream stream = response.GetResponseStream())
    using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
    {
    var jsonResponse = JsonConvert.Import<LoginResponse>(reader);
    //Console.WriteLine("\nGot Response: " + JsonConvert.Serialize<JsonResponse<T>>(jsonRespons e));
    if (jsonResponse.HasError)
    {
    throw JsonRpcClient.ReconstituteException(jsonResponse.E rror);
    }
    else
    {
    return jsonResponse.Result;
    }
    }
    }
    catch (System.Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    return new LoginResponse(); //Don't mind with this
    }
Working...
X