0

我正在开发一个从移动应用程序管理 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;
}

任何帮助将不胜感激。

4

1 回答 1

0

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

只需修改连接到 2083 的端口即可解决问题。

于 2015-07-05T12:56:19.090 回答