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


John is currently creating digital assets that protects people and their future, a technical trainer and a full time geek specializing on development and deployment of innovations created with .NET framework on Windows platform as well as Windows infrastructure projects. He is the primary contact of the Philippine Windows Users Group, a contributor at the Microsoft Philippines Community forums and regularly conducts community sessions as well as other Microsoft technology events. John owns the Busy Saving The World Techblog.

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 )

Google photo

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

Connecting to %s