Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 防止对RestSharp参数进行编码_C#_Restsharp - Fatal编程技术网

C# 防止对RestSharp参数进行编码

C# 防止对RestSharp参数进行编码,c#,restsharp,C#,Restsharp,我试图调用一个范围参数设置为t to read的OAuth2API,usercp。但是,RestSharp始终将参数编码为&scope=read%2Cusercp,而不是&scope=read,usercp 我还没有找到一种方法来禁用单个参数的编码 这是我的密码: var request = GetRequest("index.php?oauth/token", Method.POST); request.AddParameter("client_id", ClientId); request.

我试图调用一个范围参数设置为t to read的OAuth2API,usercp。但是,RestSharp始终将参数编码为&scope=read%2Cusercp,而不是&scope=read,usercp

我还没有找到一种方法来禁用单个参数的编码

这是我的密码:

var request = GetRequest("index.php?oauth/token", Method.POST);
request.AddParameter("client_id", ClientId);
request.AddParameter("client_secret", ClientSecret);

request.AddParameter("grant_type", "password");
request.AddParameter("username", username);
request.AddParameter("password", password);
request.AddParameter("scope", "read,usercp");

//request.Parameters.Add(new Parameter
//{
//    ContentType = "application/json",
//    Name = "scope",
//    Value = "read,usercp"
//});

var response = await RestClient.ExecuteTaskAsync<AuthenticateResponse>(request);
if (response.StatusCode != HttpStatusCode.OK &&
    response.StatusCode != HttpStatusCode.Accepted)
{
    throw new Exception("Could not authenticate user");
}

如何禁用该单个参数的编码?

由于我假设您希望逗号与代码中的逗号完全相同,因此建议使用逐字字符串转义。 不完全确定RestSharp如何处理此问题,但您可以尝试:

    request.AddParameter("scope", @"read,usercp");
或者单独在字符串中对其进行转义:

    var sScope = @"read,usercp";
    request.AddParameter("scope", sScope);

由于我假设您希望逗号与代码中的逗号完全相同,因此建议使用逐字字符串转义。 不完全确定RestSharp如何处理此问题,但您可以尝试:

    request.AddParameter("scope", @"read,usercp");
或者单独在字符串中对其进行转义:

    var sScope = @"read,usercp";
    request.AddParameter("scope", sScope);

根据答案,它们似乎总是被编码的。我在github上还发现了一个未解决的问题:@Phate01谢谢。也许有解决办法?我似乎找不到一个。根据答案看同样的问题,它们似乎总是被编码的。我在github上还发现了一个未解决的问题:@Phate01谢谢。也许有解决办法?我似乎找不到。请看这里的相同问题