I have a web api that has parameters. I am trying to call the api from another application. This is not a problem on the client side using, but i cannot find a way to do it on the server side in c#. Thanks for any advice.
2 Answers
You can call Web API from any desktop or server side application using WebClient.
var webClient = new WebClient();
webClient.Headers["Content-Type"] = "application/json";
webClient.Headers["X-JavaScript-User-Agent"] = "Google APIs Explorer";
var json = Newtonsoft.Json.JsonConvert.SerializeObject(new { longUrl = url });
var data = webClient.UploadString("https://www.googleapis.com/urlshortener/v1/url?pp=1", json);
1 Comment
user516883
Can you show me from the example you posted, how to send data up? like for example I have a string and a user object that I will convert to json with newtonsoft.
The link above worked perfectly for me.