I have successfully created a PHP REST API which resides on my server. I am now looking to create the client-side connection to this via my WPF C# application. I found this but my API requires the API key to be sent via a HTTP header, and I can't see you can do that in this. I also created a PHP REST client using CURL and it was very easy, and was hoping that there would be something built into C# to handle requests to REST services.
If someone could point me in the direction of a tutorial they have seen, or a library somewhere I would be grateful.
Thanks.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
Take a look at RESTSharp. Very powerful, and easy to use.
Works on all platforms too: Web, Windows, WCF, Monotouch, Windows Phone
You can just use HttpWebRequest or WebClient to make web requests like you would have with CURL in your PHP client...
If you need to deal with JSON based responses, JSON.Net is a fantastic library.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://a/rest/uri"); request.Method = "POST"; request.Headers.Add("Authorization: OAuth " + accessToken); string postData = string.Format("param1=something¶m2=something_else"); byte[] data = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "application/json"; request.ContentLength = data.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(data, 0, data.Length); } try { using(WebResponse response = request.GetResponse()) { // Do something with response } } catch (WebException ex) { // Handle error }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With