如何使用 flutter 移动应用程序在 C-Panel 中创建子域?

How to create subdomain in C-Panel using flutter mobile app?

提问人:Asiri Dhananjaya 提问时间:11/15/2023 最后编辑:Asiri Dhananjaya 更新时间:11/15/2023 访问量:9

问:

我需要使用 flutter 移动应用程序在我的网站中创建子域。当我在我的应用程序中输入子域名时,它应该在 cpanel 中生成一个子域。

Future<void> createSubdomain(String subdomainName) async {
    setState(() {
      _isLoading = true; 
    });
    try {
      const cpanelUrl = 'http://www.website.com:2082/cpanel';
      const apiKey = 'myAPI';

      final requestBody = {
        'module': 'Subdomain',
        'function': 'create',
        'domain': 'mywebsite.com',
        'subdomain': subdomainName,
        'apiversion': '2', // Use the appropriate API version
      };

      print('subDn $subdomainName');

      const username = 'uname';
      const password = 'pword`your text`';
      final credentials = utf8.encode('$username:$password');
      final base64Credentials = base64Encode(credentials);

      final headers = {
        'Authorization': 'Basic $base64Credentials',
        'Authorization-Token': apiKey, // Include the API key
      };

      final response = await http.post(
        Uri.parse('$cpanelUrl/ExecCgi'),
        headers: headers,
        body: requestBody,
      );

      if (response.statusCode == 200) {
        final jsonResponse = json.decode(response.body);
        if (jsonResponse['result'] == 1) {
          setState(() {
            _responseText = 'Subdomain created successfully!';
          });
          print(_responseText);
        } else {
          setState(() {
            _responseText = 'Error: ${jsonResponse['error']}';
          });
          print(_responseText);
        }
      } else {
        setState(() {
          _responseText = 'Error: HTTP ${response.statusCode}';
        });
        print(_responseText);
      }
    } finally {
      setState(() {
        _isLoading = false; // Set loading to false when the process completes
      });
    }
  }

此函数不会创建子域。没有回应。错误来了

[错误:flutter/runtime/dart_vm_initializer.cc(41)]未处理的异常:连接超时 E/flutter ( 9092): #0 IOClient.send (软件包:http/src/io_client.dart:94:7)

Flutter Web 部署 cPanel 移动开发

评论


答: 暂无答案