当前位置: 首页>>代码示例>>C++>>正文


C++ Response::GetBody方法代码示例

本文整理汇总了C++中http::Response::GetBody方法的典型用法代码示例。如果您正苦于以下问题:C++ Response::GetBody方法的具体用法?C++ Response::GetBody怎么用?C++ Response::GetBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http::Response的用法示例。


在下文中一共展示了Response::GetBody方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Register

bool Client::Register()
{
    Json::Value data(Json::objectValue);
    data["ip"]           = Config::getIPAddr();
    data["port"]         = Config::getListenPort();
    data["name"]         = Config::getServerName();
    data["terrain-name"] = Config::getTerrainName();
    data["max-clients"]  = Config::getMaxClients();
    data["version"]      = RORNET_VERSION;
    data["use-password"] = Config::isPublic();

    m_server_path = "/" + Config::GetServerlistPath() + "/server-list";

    Logger::Log(LOG_INFO, "Attempting to register on serverlist (%s)", m_server_path.c_str());
    Http::Response response;
    int result_code = this->HttpRequest(Http::METHOD_POST, data.toStyledString().c_str(), &response);
    if (result_code < 0)
    {
        Logger::Log(LOG_ERROR, "Registration failed, result code: %d", result_code);
        return false;
    }
    else if (result_code != 200)
    {
        Logger::Log(LOG_INFO, "Registration failed, response code: HTTP %d, body: %s", result_code, response.GetBody().c_str());
        return false;
    }

    Json::Value root;
    Json::Reader reader;
    if (!reader.parse(response.GetBody().c_str(), root))
    {
        Logger::Log(LOG_ERROR, "Registration failed, invalid server response (JSON parsing failed)");
        Logger::Log(LOG_DEBUG, "Raw response: %s", response.GetBody().c_str());
        return false;
    }

    Json::Value trust_level = root["verified-level"];
    Json::Value challenge = root["challenge"];
    if (!root.isObject() || !trust_level.isNumeric() || !challenge.isString())
    {
        Logger::Log(LOG_ERROR, "Registration failed, incorrect response from server");
        Logger::Log(LOG_DEBUG, "Raw response: %s", response.GetBody().c_str());
        return false;
    }

    m_token = challenge.asString();
    m_trust_level = trust_level.asInt();
    m_is_registered = true;
    return true;
}
开发者ID:only-a-ptr,项目名称:ror-server,代码行数:50,代码来源:master-server.cpp

示例2: RetrievePublicIp

bool RetrievePublicIp()
{
    char url[300] = "";
    sprintf(url, "/%s/get-public-ip", Config::GetServerlistPath().c_str());

    Http::Response response;
    int result_code = Http::Request(Http::METHOD_GET,
        Config::GetServerlistHostC(), url, "application/json", "", &response);
    if (result_code < 0)
    {
        Logger::Log(LOG_ERROR, "Failed to retrieve public IP address");
        return false;
    }
    Config::setIPAddr(response.GetBody());
    return true;
}
开发者ID:only-a-ptr,项目名称:ror-server,代码行数:16,代码来源:master-server.cpp

示例3: GetPublicAddress

IpAddress IpAddress::GetPublicAddress(Time timeout)
{
    // The trick here is more complicated, because the only way
    // to get our public IP address is to get it from a distant computer.
    // Here we get the web page from http://www.sfml-dev.org/ip-provider.php
    // and parse the result to extract our IP address
    // (not very hard: the web page contains only our IP address).

    Http server("www.sfml-dev.org");
    Http::Request request("/ip-provider.php", Http::Request::Get);
    Http::Response page = server.SendRequest(request, timeout);
    if (page.GetStatus() == Http::Response::Ok)
        return IpAddress(page.GetBody());

    // Something failed: return an invalid address
    return IpAddress();
}
开发者ID:coolhome,项目名称:SFML,代码行数:17,代码来源:IpAddress.cpp


注:本文中的http::Response::GetBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。