gpt4 book ai didi

c# - GoToWebinar - 请求不是预期格式 - RestSharp

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:19 25 4
gpt4 key购买 nike

类似于此论坛帖子: https://developer.citrixonline.com/forum/request-not-expected-format

但是他并没有真正解释他发现他的代码有什么问题。

我正在使用 RestSharp 进行 API 调用。我已经能够很好地使用它来提取即将举行的网络研讨会的列表,但是当我尝试注册参与者时,我不断收到 400/Request not in expected format 错误。

遵循此文档 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;

关于我如何弄清楚为什么我不断收到该错误的任何见解?

谢谢!

最佳答案

而不是使用 AddParamter(它将键/值参数添加到请求主体),您需要改为编写 JSON:

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

如果您想直接指定它们,您还需要清除处理程序(它会自动设置 Accept header ):

client.ClearHandlers();

关于c# - GoToWebinar - 请求不是预期格式 - RestSharp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10388970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com