Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Exclamation WHM XML-API using C# - Help

    Hello,
    Anyone here, used XML-API with C#, obviously from a remote windows server ?

    If so, how can use the Remote Access Key ?

    I need some light upon this, if anyone coded anything that uses whm xml-api on C#, help will be appreciated.

    Thank you
    JL

    ps. sorry for my poor english.

    (PORTUGAL)
    Last edited by serverportugal; 01-17-2009 at 05:17 PM.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Default Using WHM's XML-API on Microsoft C#

    Well, I am posting a reply to my own question, because I could achieve the result I need about using WHM's XML-API on Microsoft C#.
    To anyone with the same question I had yesterday, here's a little piece of code to help you out:

    First, add the following lines to your app.config file, or you will get an error when executing the webrequest:
    Code:
      <system.net>
        <settings>
          <httpWebRequest useUnsafeHeaderParsing = "true"/>
        </settings>
      </system.net>
    This example, suspends a CPanel account (johndoe):

    Code:
    //The url command to do what you need
    string url = "http://your-whm-server:2086/xml-api/suspendacct?user=johndoe&reason=no%20payment";
    
    WebRequest wreq = WebRequest.Create(url);
    
    //Your credentials (the same you use to login on WHM panel)
    CredentialCache MyCredential = new CredentialCache();
    MyCredential.Add(new Uri("http://your-whm-server.com:2086/"), "Basic", new NetworkCredential("your-whm-username", "your-whm-password"));
    wreq.Credentials = MyCredential;
    
    //I set the timeout to 8 seconds...
    wreq.Timeout = 8000;
    
    WebResponse wres = wreq.GetResponse();
    if (((HttpWebResponse)wres).StatusDescription == "OK")
    {
    	wres.Close(); //to free resources
    	//Code if OK
    }
    else
    {
    	wres.Close(); //to free resources
    	//Code if not OK
    }

    NOTE: Remember that to get the XML-API result, you need to write some code to read the xml stream, because the lines above based on 'HttpWebResponse', will only return the connection result to the server.

    That's it, hope it helps.
    Last edited by serverportugal; 01-18-2009 at 06:41 AM.

Similar Threads & Tags
Similar threads

  1. WHM XML API Question
    By sirbrent in forum cPanel Developers
    Replies: 1
    Last Post: 01-03-2011, 07:23 PM
  2. Starting With WHM XML API?
    By azoundria in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 01-02-2010, 02:02 AM
  3. Whm xml api
    By GMS Hosting Pro in forum New User Questions
    Replies: 0
    Last Post: 12-24-2009, 06:43 AM
  4. WHM XML API ready to use class
    By arash_hemmat in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 07-18-2008, 05:03 AM
  5. WHM XML API authentication
    By JamieD in forum cPanel Developers
    Replies: 2
    Last Post: 02-15-2008, 03:27 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube