繁体   English   中英

使用参数使用 restSharp 获取 HTTP 请求

[英]HTTP Get request with restSharp using Parameters

我在邮递员那里做了这个请求,它工作正常

在此处输入图片说明

但是当我尝试使用 RestSharp 执行相同的请求时,我得到了以下响应:

在此处输入图片说明

我的 csharp 代码:

        public string FindWeatherStation(string query)
        {
            RestClient client = new RestClient(new Uri($"https://api.meteostat.net/v2/stations/search"));
            var request = new RestRequest(Method.GET);

            request.AddHeader("x-api-key", "mykey");
            request.AddParameter("query", query);
            IRestResponse response = client.Execute(request);
            var result = response.Content;

            return result;

        }

查询值也是温哥华

我究竟做错了什么?

通过简单地将 url 作为字符串传递来创建 RestClient 对象:

RestClient client = new RestClient("https://api.meteostat.net/v2/stations/search");

然后使用ParameterType.RequestBody作为AddParameter方法的第三个参数:

request.AddParameter("query", query, ParameterType.RequestBody);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM