本文整理汇总了C++中HTTPRequest::path方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPRequest::path方法的具体用法?C++ HTTPRequest::path怎么用?C++ HTTPRequest::path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest::path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( )
{
char http_req_str1[] = "POST /abcdef/asdfasdf/ff HTTP/1.1\r\n"
"Content-Type:" ;
char http_req_str2[] = " abcdef\r";
char http_req_str3[] = "\n"
"Accept: */*\r\n"
"\r\n"
"{ 'aaaa' : 'abdef' }";
char http_rep_str1[] = "HTTP/1.1 200 OK\r\n"
"Content-Type:" ;
char http_rep_str2[] = " abcdef\r";
char http_rep_str3[] = "\n"
"Accept: */*\r\n"
"\r\n"
"{ 'aaaa' : 'abdef' }";
//HTTPService* http_server = new HTTPService( );
//http_server->listen( "localhost" , 8080 );
//http_server->on_open_session( [ ] ( Session* session )
//{
// HTTPSession* http_session = static_cast< HTTPSession* >( session );
//
// HTTPResponse * rep = new HTTPResponse();
// std::string rep_content = std::string("<body>Hello HTTP Server</body>");
// rep->content_length( rep_content.size() );
// rep->content( rep_content );
// rep->callback_send_complete( [ http_session ] ( HTTPAction* action )
// {
// http_session->close( );
// } );
// http_session->send_action( rep );
//} );
HTTPService* http_service = new HTTPService( );
http_service->connect( "www.baidu.com" , 80 );
http_service->on_open_session( [ &http_service ] ( Session* session )
{
HTTPSession * http_session = static_cast< HTTPSession* >( session );
http_session->callback_close( [ ] ( Session* s )
{
HTTPSession* http = static_cast< HTTPSession* >( s );
} );
HTTPRequest * req = new HTTPRequest();
req->path( "/" );
req->method( "GET" );
req->content_length( 0 );
req->callback_send_content( [ ] ( HTTPAction* action )
{
return nullptr;
} );
http_session->send_request( req );
} );
//HTTPRequest * req = new HTTPRequest();
//req->parse( Buffer(http_req_str1) );
//req->parse( Buffer(http_req_str2) );
//req->parse( Buffer(http_req_str3) );
//HTTPResponse * req = new HTTPResponse();
//req->parse( Buffer(http_rep_str1) );
//req->parse( Buffer(http_rep_str2) );
//req->parse( Buffer(http_rep_str3) );
while ( true )
{
uv_run( Service::loop( ) , UV_RUN_DEFAULT );
}
return 0;
}