user516883
user516883

Reputation: 9378

calling a Asp.net web API from c# with multiple of parameters

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.

Upvotes: 2

Views: 3288

Answers (2)

Asif Mushtaq
Asif Mushtaq

Reputation: 13150

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);

Upvotes: 1

Related Questions