【问题标题】:Web Api Not recognizing RestClient frameworkWeb Api 无法识别 RestClient 框架
【发布时间】:2020-10-17 08:50:53
【问题描述】:

我正在尝试对第 3 方 Web api 进行测试。 如何发布的代码由第 3 方的文档提供。

'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\":\"maryjkdfdsgfshdgf@jdfdkjdglfk.jkfgdj\"},{\"name\":\"Mike\",\"email\":\"dfdsgfsdhf@jkgfdgfkdhgfdjg.fkjgdf\"}]}", 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

【问题讨论】:

    标签: c# asp.net-mvc rest asp.net-web-api


    【解决方案1】:

    使用 RestSharp.RestClient 可以解决该错误。你不需要 RestClient 包。

    【讨论】:

      【解决方案2】:

      首先你需要卸载 RestClient 包:

      管理 -> nuget 包

      然后安装Restsharp包。

      PM -> 安装包 RestSharp

      然后使用RestSharp

      【讨论】:

        【解决方案3】:

        您似乎错过了包含用于使用 RestClient 包的命名空间。在文件顶部使用以下命名空间。

        using RestSharp;
        

        另外,你应该在使用这个 RestClient 包之前安装 nuget 包。如果未安装,则在 Nuget 包管理器控制台中使用以下命令。

        PM> install-package RestSharp
        

        【讨论】:

        • 我无法安装 RestSharp。我用原因更新了我的问题。
        • 你可以安装 Restsharp 吗?在问题描述中,您提到“我安装了 RestClient 4.0.0,但没有消除错误。”
        • 我更新了我的问题。 RestSharp 和 RestClient 已安装。解析的唯一错误:“RestClient”是一个命名空间,但用作类型
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-12
        • 1970-01-01
        • 2015-07-04
        • 2014-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多