Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.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参数的HTTP Get请求_C#_Rest_Restsharp - Fatal编程技术网

C# 使用restSharp参数的HTTP Get请求

C# 使用restSharp参数的HTTP Get请求,c#,rest,restsharp,C#,Rest,Restsharp,我在《邮递员》中提出了这个要求,效果很好 但当我尝试使用RestSharp执行相同的请求时,我得到了以下响应: 我的csharp代码: public string FindWeatherStation(string query) { RestClient client = new RestClient(new Uri($"https://api.meteostat.net/v2/stations/search"));

我在《邮递员》中提出了这个要求,效果很好

但当我尝试使用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);