Parameters 在参数不工作的情况下重新测试

Parameters 在参数不工作的情况下重新测试,parameters,get,restsharp,Parameters,Get,Restsharp,我正在调用一个web api。 Exmaple应检索名称中带有字母“a”的每个组织。 这是url,它直接针对web api工作 如果我像这样将源代码硬编码到调用函数中 RestRequest request = new RestRequest("Organisations/Get?Name=a"); // set the response data format request.RequestFormat = ReturnFormat;

我正在调用一个web api。 Exmaple应检索名称中带有字母“a”的每个组织。 这是url,它直接针对web api工作

如果我像这样将源代码硬编码到调用函数中

        RestRequest request = new RestRequest("Organisations/Get?Name=a");
        // set the response data format
        request.RequestFormat = ReturnFormat;

       var response = _restClient.Execute<List<string>>(request);
RestRequest请求=新的RestRequest(“组织/Get?Name=a”);
//设置响应数据格式
request.RequestFormat=ReturnFormat;
var response=_restClient.Execute(请求);
这个很好用。但是当我使用源为变量的格式时,参数的添加方式不同 乙二醇

string Source=“organizations”;
RestRequest请求=新的RestRequest(Source,Method.GET);
//设置响应数据格式
request.RequestFormat=ReturnFormat;
//提供任何参数
foreach(WebParameters中的RestSharp.p参数)
{
请求.添加参数(p);
}
var response=_restClient.Execute(请求);
它不起作用

我是否以正确的方式使用参数? 我是否需要在我的源代码末尾附加“/Get”呢?我采用了这个方法。Get会处理这个问题

我应该如何使用列表中的参数调用source Get方法? 对于每个方法,我的路由模板应该是什么样的

Erick

您必须附加“/get”,Method.get只指定请求类型,不向url添加任何内容(因为有时您需要一个get方法请求一个不包含“get”的url)

参数的用法似乎是正确的,因此只需更改为:

string Source = "Organisations/get";
或者,如果您在其他地方使用Source而未获得:

RestRequest request = new RestRequest(Source + "/get", Method.GET);
您必须附加“/get”,Method.get只指定请求类型,不向url添加任何内容(因为有时您需要一个get方法请求一个不包含“get”的url)

参数的用法似乎是正确的,因此只需更改为:

string Source = "Organisations/get";
或者,如果您在其他地方使用Source而未获得:

RestRequest request = new RestRequest(Source + "/get", Method.GET);

好的..所以我不能让AddParameter工作,但后来我把它改成了AddQueryParameter,它工作了

我看过Restshapr文档,但我不确定为什么一个可以工作,另一个不能


我正在调用.NETWebAPI服务,但它忽略了RestSharp请求对象中的Parameters属性。可能web api不支持这种发送参数的方法。

好的。所以我无法让AddParameter工作,但后来我将其更改为AddQueryParameter,它工作了

我看过Restshapr文档,但我不确定为什么一个可以工作,另一个不能


我正在调用.NETWebAPI服务,但它忽略了RestSharp请求对象中的Parameters属性。可能web api不支持这种发送参数的方法。

@user1413844 is you p看起来像这样:p.Name=“Name”和p.Value=“a”?@user1413844 is you p看起来像这样:p.Name=“Name”和p.Value=“a”?这是一个带有以下内容的一行代码:
var response=wait url.AppendPathSegment(“organization/get”).SetQueryParam(“Name”,val)。GetJsonAsync(); 这是一行代码:
var response=await url.AppendPathSegment(“organizations/get”).SetQueryParam(“name”,val).GetJsonAsync()