Reputation: 3375
I'm making a call to a web api. Exmaple is supposed to retrieve every organisation with the letter 'a' in the name. This is the url, and it works directly against the web api http://localhost/GMSWebServices/api/Organisations/get?name=a
If i hard code the Source into my calling function like this
RestRequest request = new RestRequest("Organisations/Get?Name=a");
// set the response data format
request.RequestFormat = ReturnFormat;
var response = _restClient.Execute<List<string>>(request);
This works fine. But when i use the format where the source is a variable and paramaters are added differently eg
string Source = "Organisations";
RestRequest request = new RestRequest(Source, Method.GET);
// set the response data format
request.RequestFormat = ReturnFormat;
//provide any paramaters
foreach (RestSharp.Parameter p in WebParamaters)
{
request.AddParameter(p);
}
var response = _restClient.Execute<List<string>>(request);
It does not work.
Am i using the Paramaters in the correct way? And do i need to append "/Get" to the end of my Source I assumed the Method.Get took care of that.
How should i be calling the source Get method with the paramaters in my list ? What should my routing template look like for each method to work ?
Erick
Upvotes: 0
Views: 1946
Reputation: 3375
Ok ..so I couldn't get AddParameter to work but then I changed it to AddQueryParameter and it worked.
I had a look at the Restshapr documentation but I'm unsure why one works and the other doesn't.
I'm calling a .net web api service but it ignores the Parameters property in the RestSharp request object. Maybe web api doesn't support this method of sending parameters.
Upvotes: 2
Reputation: 1254
You have to append "/get", the Method.GET only specify the request type, and doesn't add anything to url, (because sometimes you want a get method requesting a url that doesn't have "get" in it).
The usage of parameters seems right, so just change to that:
string Source = "Organisations/get";
or if you use Source in other places without get:
RestRequest request = new RestRequest(Source + "/get", Method.GET);
Upvotes: 0