Click here to Skip to main content
Licence CPOL
First Posted 19 May 2011
Views 7,930
Downloads 181
Bookmarked 4 times

An HTTP POST client for Windows Phone 7

By | 19 May 2011 | Technical Blog
An easy-to-use, thread-safe library which works similarly to WebClient!
A Technical Blog article. View original blog here.[^]

Silverlight and Silverlight for Windows Phone offer a great way of simplifying HTTP GET requests: WebClient class. WebClient encapsulates the primary logic of the HttpWebRequest and HttpWebResponse classes in order to receive GET data. These classes are completely transparent in most common scenarios. All the hard work is done by a WebClient object:

WebClient proxy = new WebClient();
proxy.DownloadStringCompleted += (sender, e) =>
{
    if (e.Error == null)
    {
        //Process the result...
        string data = e.Result;
    }
};
proxy.DownloadStringAsync(new Uri("http://address.com/service", UriKind.Absolute));

But how about HTTP POST requests? POST requests are critical because most mobile applications communicate via Web Services. Until today, we had to handle the HttpWebRequest and HttpWebResponse classes ourselves in order to aquire the desired data.

Not any more!

PostClient

I have just released PostClient, an easy-to-use, thread-safe library which works similarly to WebClient! Have a look:

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("name", "Vangos");
parameters.Add("age", 23);

PostClient proxy = new PostClient(parameters);
proxy.DownloadStringCompleted += (sender, e) =>
{
    if (e.Error == null)
    {
        //Process the result...
        string data = e.Result;
    }
};
proxy.DownloadStringAsync(new Uri("http://address.com/service", UriKind.Absolute));

Quite simple, huh? No HttpWebRequests, no HttpWebResponses! You only need to create a Dictionary of key-value pairs and pass it as a parameter to the PostClient's constructor. PostClient will then asynchronously download a string containing the web service data.

Downloads

» Download PostClient binaries and source code.

PostClient is an Open-Source library hosted in CodePlex and licensed under Microsoft Public License (MS-PL). You are free to use it in your applications by simply mentioning its origin. If you want to contribute for further development, do not hesitate to contact me.

Credits

Credits to Vish Uma for his great blog post considering asynchronous POST requests in Silverlight.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Vangos Pterneas

Software Developer
Freelancer
Greece Greece

Member

Follow on Twitter Follow on Twitter
I have been a student at Athens University of Economics and Business, Department of Informatics, since September 2007.
 
I mainly develop and design .NET applications in C#, ASP.NET and Silverlight, but I have also worked on J2EE, LAMP and C++.
 
Currently, I am a member of Microsoft Student Partners team and I work as a freelancer for several employers including the Institute for the Management of Information Systems and Vodafone Corporation. As a Student Partner, I have made lots of speaking engagements considering Microsoft technologies (ASP.NET, Silverlight, Windows Phone etc) to undergraduate / postgraduate students and developers.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralLicense Info PinmemberDan Colasanti20:37 15 Jun '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 19 May 2011
Article Copyright 2011 by Vangos Pterneas
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid