示例#1
0
int main( int argc, char** argv )
{
	if( argc < 4 )
	{
		printf("usage: http_tester [GET,SET,PUT] url path\n");
		return 1;
	}

#if defined( _MSC_VER )
	// Initialize Winsock
	WSADATA wsaData;
	int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
	if (iResult != 0)
	{
		printf("WSAStartup failed: %d\n", iResult);
		return 1;
	}
#endif // defined( _MSC_VER )

    http_client_t c;
    http_client_result res;

    res = http_client_connect( &c, argv[2], 0, 0, 0 );
    HTTP_ERR_CHECK( res );

    if( strcmp( argv[1], "GET" ) == 0 )
    {
		char*  msgbody;
		size_t msgbody_size;
		res = http_client_get( c, argv[3], (void**)&msgbody, &msgbody_size, 0x0 );
		HTTP_ERR_CHECK( res );

		fprintf( stdout, "%.*s\n", (int)msgbody_size, msgbody );
		free( msgbody );
    }
    else if( strcmp( argv[1], "HEAD" ) == 0 )
    {
		size_t msgbody_size;
		res = http_client_head( c, argv[3], &msgbody_size);
		HTTP_ERR_CHECK( res );

		printf( "content size: %lu\n", msgbody_size );
    }

    else if( strcmp( argv[1], "PUT" ) == 0 )
	{
		res = http_client_put( c, argv[3], "apansson", 9 );
		HTTP_ERR_CHECK( res );
	}

    http_client_disconnect( c );
    free( c );

    return 0;
}
示例#2
0
int http_client_demo(void)
{
	int idle_count = 0,command;
	rtp_net_init();
	rtp_threads_init();

	while ((command = prompt_for_command()) != COMMAND_QUIT)
	{
	HTTPManagedClient httpClient;
		if (http_client_init(&httpClient) < 0)
			return(-1);
		if (command == COMMAND_GET)
			http_client_get(&httpClient,0);
		else if (command == COMMAND_GETTO_FILE)
			http_client_get(&httpClient,1);
		else if (command == COMMAND_POST)
			http_client_post(&httpClient);
		else if (command == COMMAND_PUT)
			http_client_put(&httpClient);
	}
	rtp_net_exit();
	return (0);

}