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


C++ HttpClient::GetErrorMessage方法代码示例

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


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

示例1:

TEST_F(HttpClientTest, GetWithoutProxy)
{
    HttpClient client;
    HttpResponse response;
    HttpClient::Options options;
    options.AddHeader("Content-Type", "text/plain");
    client.SetUserAgent("TestDownloader");
    HttpClient::ErrorCode error;
    EXPECT_TRUE(client.Get(m_server_address + "/robots.txt", &response, &error));
    EXPECT_EQ(HttpClient::SUCCESS, error);
    EXPECT_EQ(HttpResponse::Status_OK, response.Status());
    EXPECT_FALSE(response.Body().empty());

    EXPECT_FALSE(client.Get(m_server_address + "/world", &response, &error));
    EXPECT_EQ(HttpClient::ERROR_HTTP_STATUS_CODE, error);
    EXPECT_EQ(HttpResponse::Status_NotFound, response.Status());

    EXPECT_FALSE(client.Get("http://127.0.0.1:8/world", &response, &error));
    EXPECT_EQ(HttpClient::ERROR_FAIL_TO_CONNECT_SERVER, error);
    EXPECT_STREQ("Failed to connect to server", client.GetErrorMessage(error));

    // FIXME(chen3feng) : On some env, below cases will fail.
    //  EXPECT_FALSE(client.Get("http://non-exist-domaon.test/world", &response, &error));
    //  EXPECT_EQ(HttpClient::ERROR_FAIL_TO_RESOLVE_ADDRESS, error);
    //  EXPECT_STREQ("Failed to resolve address", client.GetErrorMessage(error));

    // not supported scheme
    EXPECT_FALSE(client.Get("ftp://127.0.0.1/hello.txt", &response, &error));

    // Receive with small response length
    HttpClient client2;
    options.SetMaxResponseLength(3);
    EXPECT_FALSE(client2.Get(m_server_address + "/hello.txt", options, &response, &error));
    // room is not enough to store a complete http response header
    EXPECT_NE(error, HttpClient::SUCCESS);
}
开发者ID:KangRoger,项目名称:toft,代码行数:36,代码来源:client_test.cpp


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