问题
我需要使用 C# 对 Betfair API 进行 cUrl 调用。调用是尝试使用当前注册的详细信息获得登录访问权限。我尝试使用的方法在 API 文档中描述为使用 API 端点的交互式登录。我没有使用 cUrl 的经验,所以非常不确定如何使它工作。
我正在尝试进行的调用的 API 文档页面。
需要调用
curl -k -i -H "Accept: application/json" -H "X-Application: <AppKey>" -X POST -d 'username=<username>&password=<password>' https://identitysso.betfair.com/api/login
进步
在过去,我以以下方式使用 HttpRequest。
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();
从我读到的内容来看,我应该在进行 cUrl 调用时使用 HttpClient,但因为在我发现很难解决之前我从未这样做过。
以下代码是我迄今为止尝试过的,但它似乎不起作用。
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());
}
任何帮助将不胜感激。提前致谢。