0

問題

Betfair API に対して C# を使用して cUrl 呼び出しを行う必要があります。この呼び出しは、現在登録されている詳細を使用してログイン アクセスを取得しようとするものです。使用しようとしている方法は、API エンドポイントを使用した対話型ログインとして API ドキュメントに記載されています。cUrl を使用した経験がないため、どのように機能させるかが非常にわかりません。

私が行おうとしている呼び出しの API ドキュメント ページ。

https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/インタラクティブ+ログイン+-+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());
}

どんな助けでも大歓迎です。前もって感謝します。

4

0 に答える 0