The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cPanel API Question

Discussion in 'cPanel Developers' started by msbayir, Dec 21, 2009.

  1. msbayir

    msbayir Registered

    Joined:
    Dec 21, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Can I use cPanel API with C#?

    If i can, can you write me little example.

    For example gethostname.

    Regards.
     
  2. msbayir

    msbayir Registered

    Joined:
    Dec 21, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I can do that but with cPanel 11.25 i got error ;

    Server Error in '/API-For-cPanel' Application.
    The remote server returned an error: (403) Forbidden.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.WebException: The remote server returned an error: (403) Forbidden.

    Anyone can help me?
     
  3. mitt

    mitt Member

    Joined:
    May 11, 2004
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Having the same problem.

    //The url command to do what you need
    string url = "https://werer.werwer.com:2087/xml-api/listaccts";

    WebRequest wreq = WebRequest.Create(url);

    //Your credentials (the same you use to login on WHM panel)
    CredentialCache MyCredential = new CredentialCache();
    MyCredential.Add(new Uri("https://werer.werwer.com:2087/"), "Basic", new NetworkCredential("root", "password"));
    wreq.Credentials = MyCredential;
    ((HttpWebRequest)wreq).UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)";

    wreq.Timeout = 8000;

    WebResponse wres = wreq.GetResponse();

    Any ideas??
     
  4. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    What you are facing is that most of the .NET libraries that I have encountered for handling HTTP Basic Authentication rely on the server requesting authentication. cPanel does not operate in this fashion as it expects the authentication request to be sent with the initial request. I have a completely untested code sample that may help you with this, but I am not a C# coder, nor do I have a windows machine handy to test this... so before I put potentially bad code info out there, I'll send you to this blog post:

    Project 20: Assigning Basic Authorization HTTP Header to HttpWebRequest

    Which discusses the problem you are encountering along with some code on how to fix it.

    Please update if you need further assistance.
     
Loading...

Share This Page