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


C++ Connection::Request方法代码示例

本文整理汇总了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 );
}
开发者ID:sinsoku,项目名称:cacoon,代码行数:14,代码来源:HttpClient.cpp

示例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;
		}
开发者ID:sinsoku,项目名称:cacoon,代码行数:31,代码来源:SlowHttpTest.cpp

示例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;
		}
开发者ID:sinsoku,项目名称:cacoon,代码行数:31,代码来源:SlowHttpsTest.cpp


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