Question

I just started taking a class on C# .NET and have found it really fascinating how simple it is. I have been using C++ for years, so the simplistic nature is actually hitting me as somewhat confusing.

I would like to do something along these lines...

http://wiki.whmcs.com/API:Example_Usage

Would it be easy to do this from a C# .NET application, or would I still be in about the same boat as C++ (build libcurl, grab a bunch of other libs, etc)?

Was it helpful?

Solution

You could create and instance of WebClient thus:

 // Instantiate the WebClient object
 WebClient WHMCSclient = new WebClient();

 // Prepare a Name/Value collection to hold the post values
 NameValueCollection form = new NameValueCollection();      
 form.Add("username", username);
 form.Add("password", password); // the password will still need encoding is MD5 is a requirement
 form.Add("action", "addinvoicepayment"); // action performed by the API:Functions
 form.Add("invoiceid", "1");
 form.Add("transid", "TEST");
 form.Add("gateway", "mailin");

 // Post the data and read the response
 Byte[] responseData = WHMCSclient.UploadValues("http://www.yourdomain.com/whmcs/includes/api.php", form);      

 // Decode and display the response.
 Console.WriteLine("\nResponse received was \n{0}",Encoding.ASCII.GetString(responseData));

I've not had a chance to test that but this snippet should at least have you working along the right lines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top