【问题标题】:RestSharp and multiple request parameter typeRestSharp 和多个请求参数类型
【发布时间】:2018-05-06 18:49:47
【问题描述】:

我有使用密钥进行授权的api,第二个参数是方法。当我使用 RequestBody 参数类型的另一个参数执行请求时,会出现问题。 RestSharp 文档说我不能将默认的GetOrPost 参数类型与RequestBody 参数类型一起使用,因为RequestBody 的参数将被GetOrPost 覆盖。

我尝试通过 UrlSegment 或 Authenticators 等其他方法进行授权,但 api 仅接受具有 GetOrPost 参数类型的密钥。

当我发送带有GetOrPost 类型的第三个参数时,它不起作用。

这是我使用的代码:

            var request = new RestRequest(Method.POST);
            var key = "11ECR0D5T9BIAC5DLXXGZ";
            var client = new RestClient(url);

            request.RequestFormat = DataFormat.Json;         
            request.AddParameter("key", key);
            request.AddParameter("method", "getProducts");
            request.AddParameter("application/json","{id:1}");

有什么方法可以授权其他参数类型吗?还是将 id 参数作为其他参数类型发送?

【问题讨论】:

  • 抱歉,一定是误点击

标签: json rest api restsharp


【解决方案1】:

我自己解决了,我错过了参数必须命名为“参数”,所以它看起来像:request.AddParameter("parameters",jsonParam);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多