Sending data to and receiving data from a resource identified by a URI thru WebClient


As I have posted on about using a System.Net.WebClient to "Post" a Collection instead of posting this string postData = "client_id=" + 318 + "&tracking_id=" + 2000 thru HttpWebRequest. You can use this:

   1:  //Declare your Name-value Collection
   2:  System.Collections.Specialized.NameValueCollection objCollectionToPost = new NameValueCollection(2);
   4:  //populate your collection
   5:   objCollectionToPost.Add(“client_id”, 318);
   6:   objCollectionToPost.Add(“tracking_id”, 2000);
   8:  //Instantiate  your System.Net.WebClient
   9:  WebClient objClient = new WebClient();
  10:  objClient.BaseAddress = “https:/”; 
  12:  //To capture the response, you may use a byte[ array or a long string, your implementation
  13:  //would depend on what you think is the response will be
  14:  // for this instance I will use a byte array (you will notice why siguro at the end)
  16:  Byte objResponseCollection;
  18:  //This is the actual posting, you would notice that when you UploadValues to the 
  19:  objResponseCollection = objClient.UploadValues(objClient.BaseAddress, "POST", objCollectionToPost);
  21:  //since most likely it would be a length of bytes, and I know from the documentation of your payment
  23:  //gateway, that this will be a “Comma Delimited” string, I will process it as follows
  25:  String objRetValues;
  26:  objRetValues = System.Text.Encoding.ASCII.GetString(objResponseCollection).Split(",".ToCharArray());
When you post WebClient usually returns the response of the payment gateway. 
The response is usually a long string that you need to split into a specified delimiter. 
In my example I already know that the gateway will return a "Comma Delimited" String based on the documentation I got from the payment provider.
For more info on WebClient go to msdn:

Published by


I'm John and in the daytime I am the Chief Technology Officer of VFTS.NET - a consulting firm that specializes on development and deployment of business solutions created with .NET framework on Windows platform and Windows infrastructure projects. I am a core member of the Philippine Windows Users Group, a contributor at the Microsoft Philippines Community forums and I regularly conduct technical sessions as well as other Microsoft technology events. I am a Microsoft Most Valuable Professional in the Cloud and Datacenter Management Technical Expertise but away from any keyboard I spend hours reading books, travel, explore, and being busy with my dog named Floppy.

Leave a Reply

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

You are commenting using your 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