cPanel API-不允许在webmail(api2)内部执行



我正在开发一个应用程序来管理移动应用程序中的cPanel帐户,但首先我将作为一个简单的windows窗体应用程序进行概念验证。用户应该能够使用他们的用户名和密码进行身份验证。

然而,无论我尝试执行什么操作,我总是得到以下响应:

<Root>
  <cpanelresult>
    <apiversion>2</apiversion>
    <error>Execution of Email::addpop is not permitted inside of webmail (api2)</error>
    <func>addpop</func>
    <data>
      <reason>Execution of Email::addpop is not permitted inside of webmail (api2)</reason>
      <result>0</result>
    </data>
    <module>Email</module>
  </cpanelresult>
</Root>

我尝试过的每个函数都会出现此错误。cPanel帐户的功能列表中包含所有功能。

我使用以下代码来调用API:

表单

Communication com = new Communication();
string result = com.SendRequest("Email", "addpop",
                "&domain ='apitest.DOMAIN.nl'&email='user'&password='12345luggage'&quota='500'");
txtOutput.Text = result;

通信类

public string SendRequest(string module, string function, string extra = "")
{
    try
    {
        var httpWebRequest =
            (HttpWebRequest) WebRequest.Create(Settings.Default.Server +
                                                string.Format(
                                                    "/json-api/cpanel?cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module={0}&cpanel_jsonapi_func={1}{2}",
                                                    module, function, extra));
        httpWebRequest.Accept = "*/*";
        httpWebRequest.Method = "GET";
        string credentials = (username + ":" + password).Base64Encode();
        httpWebRequest.Headers.Add("Authorization: Basic " + credentials);
        var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse();

        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            string answer = streamReader.ReadToEnd();
            XNode node = JsonConvert.DeserializeXNode(answer, "Root");
            return node.ToString();
        }
    }
    catch (WebException ex)
    {
        switch (ex.Status)
        {
            case WebExceptionStatus.ProtocolError:
                return ((HttpWebResponse) ex.Response).StatusCode.ToString();
            case WebExceptionStatus.NameResolutionFailure:
                return "Could not find specified domain: " +
                        ex.Status.ToString();
        }
    }
    return null;
}

如有任何帮助,我们将不胜感激。

问题是由使用错误的端口引起的。尽管我认为我检查了多次端口,但我确实连接到了网络邮件端口(2087),而不是cPanel端口(2083)

简单地修改连接到2083的端口就解决了这个问题。

最新更新