2

このフォーラムの投稿と同様: https ://developer.citrixonline.com/forum/request-not-expected-format

しかし、彼は自分のコードで何が間違っているのかを実際には説明しませんでした。

私はRestSharpを使用してAPI呼び出しを行っています。今後のウェビナーのリストを取得するためにうまく機能させることができましたが、参加者を登録しようとすると、予期しない形式のエラーではない400/Requestが発生し続けます。

このドキュメントhttps://developer.citrixonline.com/api/gotowebinar-rest-api/apimethod/create-registrantに従って、ここに私のコードがあります:

var client = new RestClient(string.Format("https://api.citrixonline.com/G2W/rest/organizers/{0}/webinars/{1}/registrants", "300000000000xxxxxx", btn.CommandArgument));
var request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;

request.AddHeader("Accept", "application/json");
request.AddHeader("Accept", "application/vnd.citrix.g2wapi-v1.1+json");
request.AddHeader("Authorization", "OAuth oauth_token=" + System.Configuration.ConfigurationManager.AppSettings["GoToWebinar"]);

request.AddParameter("firstName", LoggedInUser.FirstName);
request.AddParameter("lastName", LoggedInUser.LastName);
request.AddParameter("email", LoggedInUser.Email);

var response = client.Execute(request);
var statusCode = response.StatusCode;

なぜそのエラーが発生し続けるのかを理解する方法についての洞察はありますか?

ありがとうございました!

4

1 に答える 1

1

AddParamter(キー/値パラメーターをリクエスト本文に追加する)を使用する代わりに、代わりにJSONを記述する必要があります。

request.DataFormat = DataFormat.Json;
request.AddBody(new {
    firstName = LoggedInUser.FirstName,
    lastName = LoggedInUser.LastName,
    email = LoggedInUser.Email
});

ハンドラーを直接指定する場合は、ハンドラー(Acceptヘッダーを自動的に設定する)もクリアする必要があります。

client.ClearHandlers();
于 2012-04-30T20:17:55.473 に答える