Posting data to a REST service using C#

  1. public void SendMessage( string endPoint, Dictionary< string, string > paramters)
  2. {
  3. var populatedEndPoint = CreateFormattedPostRequest( paramters );
  4. byte[] bytes = Encoding.UTF8.GetBytes( populatedEndPoint );
  5. HttpWebRequest request = CreateWebRequest( endPoint, bytes.Length );
  6. using ( var requestStream = request.GetRequestStream() )
  7. {
  8. requestStream.Write( bytes, 0, bytes.Length );
  9. }
  10. using ( var response = (HttpWebResponse)request.GetResponse() )
  11. {
  12. if ( response.StatusCode != HttpStatusCode.OK )
  13. {
  14. string message = String.Format( “POST failed. Received HTTP {0}”, response.StatusCode );
  15. throw new ApplicationException( message );
  16. }
  17. }
  18. }

About eagle081183

Passionate, Loyal
This entry was posted in C#, SOA, Software architecture. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s