cyanray / mirai-cpp

本项目为 mirai-api-http 的 C++ 封装,方便使用 C++ 开发基于 mirai-api-http 插件。
GNU Affero General Public License v3.0
148 stars 38 forks source link

使用Auth函数时抛出“网络错误”异常 #54

Closed dbxxx-ac closed 3 years ago

dbxxx-ac commented 3 years ago
    while (true)
    {
        try
        {
            bot.Auth("zql740125", 3466211762_qq);
            break;
        }
        catch (const std::exception& ex)
        {
            cout << ex.what() << endl;
        }
        MiraiBot::SleepSeconds(1);
    }

保证Authkey是正确的,QQ号也是正确的,mirai-console也在正常运行,可是依旧抛出“网络错误”的异常。保证网络没有问题。

请问是怎么回事呢?

dbxxx-ac commented 3 years ago

哦对了,补充一条:我已经安装且正确配置了mirai-http-api插件。

cyanray commented 3 years ago
/**
 * \brief MiraiBot的另一个构造函数
 * \param host hostname
* \param port port
*/
MiraiBot(const string& host, int port);

不知道你有没有修改默认的端口,如果修改了,实例化MiraiBot对象的时候是需要设置的。 比如:

MiraiBot bot("localhost",8889);

如果不指定(MiraiBot bot;),host和port的默认值是"localhost"8080

如果是连接的远程服务器,试一下用浏览器访问 http://hostname:port/about (例如 http://baidu.com:1234/about),检查能不能正确返回 mirai-api-http 的版本信息。

dbxxx-ac commented 3 years ago
/**
 * \brief MiraiBot的另一个构造函数
 * \param host hostname
* \param port port
*/
MiraiBot(const string& host, int port);

不知道你有没有修改默认的端口,如果修改了,实例化MiraiBot对象的时候是需要设置的。 比如:

MiraiBot bot("localhost",8889);

如果不指定(MiraiBot bot;),host和port的默认值是"localhost"8080

如果是连接的远程服务器,试一下用浏览器访问 http://hostname:port/about (例如 http://baidu.com:1234/about),检查能不能正确返回 mirai-api-http 的版本信息。

感谢回复!

并没有修改默认的端口,连接的也不是远程服务器。

cyanray commented 3 years ago
/**
 * \brief MiraiBot的另一个构造函数
 * \param host hostname
* \param port port
*/
MiraiBot(const string& host, int port);

不知道你有没有修改默认的端口,如果修改了,实例化MiraiBot对象的时候是需要设置的。 比如:

MiraiBot bot("localhost",8889);

如果不指定(MiraiBot bot;),host和port的默认值是"localhost"8080 如果是连接的远程服务器,试一下用浏览器访问 http://hostname:port/about (例如 http://baidu.com:1234/about),检查能不能正确返回 mirai-api-http 的版本信息。

感谢回复!

并没有修改默认的端口,连接的也不是远程服务器。

那使用浏览器访问 http://127.0.0.1:8080/about 是否能获取到 mirai-api-http 的版本信息。

dbxxx-ac commented 3 years ago

问题解决了……qwq

重装了一下mirai-cpp-template,问题得到了解决。