2

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 2

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

http://weblogs.asp.net/pglavich/archive/2012/02/18/mvc4-and-web-api-make-an-api-the-way-you-always-wanted-part-1.aspx

The link above worked perfectly for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.