2017-04-07 6 views
1

OAuth2 APIをスコープパラメータセットt o read,usercpでコールしようとしています。しかしRestSharpは常に&scope=read%2Cusercpにパラメータをエンコードします。代わりに&scope=read,usercpRestSharpパラメータのコード化を防止する

私はまだ単一のパラメータのエンコードを無効にする方法を見つけていません。

は、ここに私のコードです:

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"); 
} 

私は、単一のパラメータのエンコーディングを無効にするにはどうすればよいですか?

+0

[この]に基づいて(http://stackoverflow.com/ A/22166701/4499267)答え、彼らは常にエンコードされているようです。 githubに関する未解決の問題も見つかりました:http://github.com/restsharp/RestSharp/issues/892 – Phate01

+0

@ Phate01ありがとうございます。たぶんそこには回避策がありますか?私は見つけられないようです。 – SeToY

答えて

-1

コンマをコードに書いたとおりに扱いたいと思うので、私は逐語的な文字列をエスケープすることをお勧めします。 RestSharpがこれをどのように処理するか完全にわからないが、あなたは試すことができいずれか:

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

か、別途、文字列でそれをエスケープする:

var sScope = @"read,usercp"; 
    request.AddParameter("scope", sScope); 
関連する問題