简体   繁体   中英

HTTP Get request with restSharp using Parameters

I did this request in postman and it works fine

在此处输入图片说明

But when I try to do the same request using RestSharp I´m having this response:

在此处输入图片说明

my csharp code:

        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;

        }

the query value is vancouver as well

What am I doing wrong?

Creating the RestClient object by simply pass the url as string:

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

Then using ParameterType.RequestBody as the third parameter to the AddParameter method:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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