本文整理汇总了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);
}