本文整理汇总了C++中Connection::Request方法的典型用法代码示例。如果您正苦于以下问题:C++ Connection::Request方法的具体用法?C++ Connection::Request怎么用?C++ Connection::Request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::Request方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Connect
// URL に簡単にアクセスするための静的メソッド
Response HttpClient::Connect( const std::string & method, const std::string & url, const HeaderMap & header )
{
int prefixLength = url.find( "://" ) + 3; // "https://" の長さ
int rootLength = url.substr( prefixLength ).find( "/" );
std::string root = url.substr( prefixLength, rootLength ); // "https://(xxxx)/**" の (xxxx) を抽出
std::string endpoint = url.substr( prefixLength + rootLength ); // 上の (xxxx) 以降を抽出
Connection conn = ( url.substr( 0, 5 ) == "https" )
? HttpClient::CreateHttpsConnection( root )
: HttpClient::CreateHttpConnection( root );
return conn.Request( "GET", endpoint, header );
}
示例2:
// 簡易接続のテスト
TEST( HttpConnectionTest, EasyRequest )
{
Response resp = HttpClient::Connect( Method::Get, "http://cacoo.com/" );
EXPECT_EQ( 200, resp.StatusCode() );
}
// 複数回のレスポンスのテスト
TEST( HttpConnectionTest, MultiRequest )
{
EXPECT_NO_THROW(
{
try
{
Connection c = HttpClient::CreateHttpConnection( "cacoo.com" );
Response res1st = c.Request( Method::Get, "/" );
Response res2nd = c.Request( Method::Get, "/features" );
EXPECT_EQ( 200, res1st.StatusCode() );
EXPECT_EQ( 200, res2nd.StatusCode() );
Connection c2 = c;
Response res3rd = c2.Request( Method::Get, "/" );
EXPECT_EQ( 200, res3rd.StatusCode() );
}
catch( const CacoonException & ex )
{
std::cout << ex.Info() << std::endl;
throw;
}
示例3:
EXPECT_EQ( 200, resp.StatusCode() );
std::cout << resp.Body();
}
// HTTPS の複数回リクエスト
TEST( HttpsConnectionTest, MultiRequest )
{
EXPECT_NO_THROW(
{
try
{
const std::string host = "cohama.backlog.jp";
const std::string url = "/LoginDisplay.action;jsessionid=E3E47A1EE360473E09AAB64426083937.h";
Connection conn = HttpClient::CreateHttpsConnection( host );
Response res1st = conn.Request( Method::Get, url );
Response res2nd = conn.Request( Method::Get, url );
conn = HttpClient::CreateHttpsConnection( host );
Response res3rd = conn.Request( Method::Get, url );
EXPECT_EQ( 200, res1st.StatusCode() );
EXPECT_EQ( 200, res2nd.StatusCode() );
EXPECT_EQ( 200, res3rd.StatusCode() );
}
catch( const CacoonException & ex )
{
std::cout << ex.Info() << std::endl;
throw;
}