Reputation: 181
The Problem
I need to make a cUrl call using C# to the Betfair API. The call is to try gain login access using currently registered details. The method im trying to use is described in the API documentation as an Interactive Login using the API Endpoint. I have no experience using cUrl so very unsure how to make it work.
API Documentation page for the call I am trying to make.
Required Call
curl -k -i -H "Accept: application/json" -H "X-Application: <AppKey>" -X POST -d 'username=<username>&password=<password>' https://identitysso.betfair.com/api/login
Progress
In the past I have used HttpRequest
in the following way:
HttpWebRequest request =(HttpWebRequest)WebRequest.Create("http://api.football-data.org/v1/soccerseasons/354/fixtures/?matchday=22");
request.Headers.Add("AUTHORIZATION", "Basic YTph");
request.ContentType = "text/html";
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader stream = new StreamReader(response.GetResponseStream());
string ResultAsText = stream.ReadToEnd().ToString();
From what I have read I should using HttpClient
when making cUrl calls but as I have never done this before I'm finding it difficult to work it out.
The following code is what I have tried so far but it does not seem to work.
using System.Net.Http;
var client = new HttpClient();
// Create the HttpContent for the form to be posted.
var requestContent = new FormUrlEncodedContent(new [] {
new KeyValuePair<string, string>("text", "username=<username>&password=<password>"),
});
// Get the response.
HttpResponseMessage response = await client.PostAsync(
"https://identitysso.betfair.com/api/login",
requestContent);
// Get the response content.
HttpContent responseContent = response.Content;
// Get the stream of the content.
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
// Write the output.
Console.WriteLine(await reader.ReadToEndAsync());
}
Any help would be greatly appreciated.
Upvotes: 0
Views: 1079