我正在尝试对第 3 方 Web API 进行测试。 如何发布的代码由第三方文档提供。
'RestClient' is a namespace but is used like a type
The type or namespace name 'RestRequest' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'IRestResponse' could not be found (are you missing a using directive or an assembly reference?)
The name 'ParameterType' does not exist in the current context
The name 'Method' does not exist in the current context
我正在使用的方法:
public void CreatePanelists (Newtonsoft.Json.Linq.JObject data)
{
Parameters parameters = JsonConvert.DeserializeObject<Parameters>(data.ToString())
IList<Panelist> panelistList = parameters.panelists;
string id = parameters.id;
var client = new RestClient("https://3rdparty.com/v2/events/5893/atendees");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer vJRMZ92lsOE1sKGVF7_4zCezTjxO2RoFeOVGULSJS2_dRhgU5QfZeKqGaoS0ogPv0WISEuZ1RcNzJDUsv27uGA");
request.AddParameter("application/json", "{\"attendees\":[{\"name\":\"Mary\",\"email\":\"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aac7cbd8d3c0c1ceccced9cdccd9c2cecdcceac0cecccec1c0cecdc6ccc184c0c1cccdcec0" rel="noreferrer noopener nofollow">[email protected]</a>\"},{\"name\":\"Mike\",\"email\":\"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f195979582969782959997b19b9a96979596979a95999697959b96df979a9b969597" rel="noreferrer noopener nofollow">[email protected]</a>\"}]}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
}
我安装了 RestClient 4.0.0,但这并没有消除错误。
我没有使用.Net,而不是.net Core。我错过了什么?
第一次开发此类项目,如果我的技术语言不正确,请原谅。
非常感谢您的帮助。
谢谢你, 伊拉斯莫
更新 - 我能够安装 RestSharp 版本 106.11.4.0 和 RestClient 版本 2.5.0.6。
唯一持续存在的错误是
'RestClient' is a namespace but is used like a type
最佳答案
您似乎错过了包含使用 RestClient 包的命名空间。在文件顶部使用以下命名空间。
using RestSharp;
此外,您应该在使用此 RestClient 包之前安装 nuget 包。如果未安装,则在 Nuget 包管理器控制台中使用以下命令。
PM> install-package RestSharp
关于c# - Web Api 无法识别 RestClient 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62600048/