不要在 RestSharp 中编码参数 [英] Do not encode parameters in RestSharp
问题描述
我正在使用 RestSharp 访问 RubyOnRails API.您可能知道,RoR 喜欢参数名称采用 model_name[property]
形式.另一方面,RestSharp 不喜欢它.
Fiddler 说我将它发送到服务器:
user%5Bemail%5D=user%40email.com&user%5Bpassword%5D=test
看起来 R# 在发送数据时对参数和值都进行了编码(与 Curl 不同,它看起来像是有选择地编码).虽然我猜大多数时候这很好,但在这种特殊情况下,它会使 API 返回 401,因为它不理解参数.
是否可以要求 R# 不对请求的参数进行编码?
谢谢!
编辑
好的,在 R# 源代码中,我找到了 RestClient.EncodeParameters 方法,所以看起来参数的名称总是经过编码的.我想我将不得不分叉它:(
在 RestSharp 源代码中 我发现参数总是被编码(包括名称和值),所以我想如果我想添加一个额外的参数,我将不得不分叉它.>
I am using RestSharp to access a RubyOnRails API.
As you might know, RoR likes when the parameters names are in the form model_name[property]
. RestSharp, on the other hand, does not like it.
Fiddler says I send this to the server :
user%5Bemail%5D=user%40email.com&user%5Bpassword%5D=test
It looks like R# encodes both the parameters and values when it sends the data (unlike Curl, which looks like it encodes selectively). While that's fine most of the time I guess, in this particular case, it makes the API return a 401 because it doesn't understand the parameters.
Is it possible to ask R# to not encode the request's parameters ?
Thank you !
Edit
Ok, in the R# sources, I found the method RestClient.EncodeParameters, so it looks like the parameter's name is always encoded. I guess I will have to fork it :(
In the RestSharp sources I found out that the parameters are always encoded (both the name and the value), so I guess that I will have to fork it if I want to add an additional parameter.
这篇关于不要在 RestSharp 中编码参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!