Index: pjproject/trunk/pjlib-util/src/pjlib-util-test/http_client.c
===================================================================
--- pjproject/trunk/pjlib-util/src/pjlib-util-test/http_client.c	(revision 3095)
+++ pjproject/trunk/pjlib-util/src/pjlib-util-test/http_client.c	(revision 3147)
@@ -271,4 +271,5 @@
     pj_http_req_callback hcb;
     pj_http_req_param param;
+    char urlbuf[80];
 
     pj_bzero(&hcb, sizeof(hcb));
@@ -287,10 +288,8 @@
 #ifdef USE_LOCAL_SERVER
 
-    pj_cstr(&url, "http://127.0.0.1:8080/about-us/");
     thread_quit = PJ_FALSE;
     g_server.action = ACTION_REPLY;
     g_server.send_content_length = PJ_TRUE;
     g_server.data_size = 2970;
-    g_server.port = 8080;
     g_server.buf_size = 1024;
 
@@ -300,9 +299,22 @@
         return -41;
 
-    pj_sockaddr_in_init(&addr, NULL, (pj_uint16_t)g_server.port);
+    pj_sockaddr_in_init(&addr, NULL, 0);
 
     sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr));
     if (sstatus != PJ_SUCCESS)
         return -43;
+
+    {
+	pj_sockaddr_in addr;
+	int addr_len = sizeof(addr);
+	sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len);
+	if (sstatus != PJ_SUCCESS)
+	    return -44;
+	g_server.port = pj_sockaddr_in_get_port(&addr);
+	pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
+			 "http://127.0.0.1:%d/about-us/",
+			 g_server.port);
+	url = pj_str(urlbuf);
+    }
 
     sstatus = pj_sock_listen(g_server.sock, 8);
@@ -367,4 +379,5 @@
     pj_http_req_param param;
     pj_time_val timeout;
+    char urlbuf[80];
 
     pj_bzero(&hcb, sizeof(hcb));
@@ -390,5 +403,4 @@
     g_server.send_content_length = PJ_FALSE;
     g_server.data_size = 4173;
-    g_server.port = 380;
     g_server.buf_size = 1024;
 
@@ -398,9 +410,22 @@
         return -41;
 
-    pj_sockaddr_in_init(&addr, NULL, (pj_uint16_t)g_server.port);
+    pj_sockaddr_in_init(&addr, NULL, 0);
 
     sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr));
     if (sstatus != PJ_SUCCESS)
         return -43;
+
+    {
+	pj_sockaddr_in addr;
+	int addr_len = sizeof(addr);
+	sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len);
+	if (sstatus != PJ_SUCCESS)
+	    return -44;
+	g_server.port = pj_sockaddr_in_get_port(&addr);
+	pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
+			 "http://127.0.0.1:%d",
+			 g_server.port);
+	url = pj_str(urlbuf);
+    }
 
     sstatus = pj_sock_listen(g_server.sock, 8);
@@ -487,4 +512,5 @@
     char *data;
     int length = 3875;
+    char urlbuf[80];
 
     pj_bzero(&hcb, sizeof(hcb));
@@ -501,10 +527,8 @@
 
 #ifdef USE_LOCAL_SERVER
-    pj_cstr(&url, "http://127.0.0.1:380/test/test.txt");
     thread_quit = PJ_FALSE;
     g_server.action = ACTION_REPLY;
     g_server.send_content_length = PJ_TRUE;
     g_server.data_size = 0;
-    g_server.port = 380;
     g_server.buf_size = 4096;
 
@@ -514,9 +538,22 @@
         return -41;
 
-    pj_sockaddr_in_init(&addr, NULL, (pj_uint16_t)g_server.port);
+    pj_sockaddr_in_init(&addr, NULL, 0);
 
     sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr));
     if (sstatus != PJ_SUCCESS)
         return -43;
+
+    {
+	pj_sockaddr_in addr;
+	int addr_len = sizeof(addr);
+	sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len);
+	if (sstatus != PJ_SUCCESS)
+	    return -44;
+	g_server.port = pj_sockaddr_in_get_port(&addr);
+	pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
+			 "http://127.0.0.1:%d/test/test.txt",
+			 g_server.port);
+	url = pj_str(urlbuf);
+    }
 
     sstatus = pj_sock_listen(g_server.sock, 8);
@@ -576,4 +613,5 @@
     pj_http_req_callback hcb;
     pj_http_req_param param;
+    char urlbuf[80];
 
     pj_bzero(&hcb, sizeof(hcb));
@@ -591,10 +629,8 @@
 
 #ifdef USE_LOCAL_SERVER
-    pj_cstr(&url, "http://127.0.0.1:380/test/test2.txt");
     thread_quit = PJ_FALSE;
     g_server.action = ACTION_REPLY;
     g_server.send_content_length = PJ_TRUE;
     g_server.data_size = 0;
-    g_server.port = 380;
     g_server.buf_size = 16384;
 
@@ -604,9 +640,22 @@
         return -41;
 
-    pj_sockaddr_in_init(&addr, NULL, (pj_uint16_t)g_server.port);
+    pj_sockaddr_in_init(&addr, NULL, 0);
 
     sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr));
     if (sstatus != PJ_SUCCESS)
         return -43;
+
+    {
+	pj_sockaddr_in addr;
+	int addr_len = sizeof(addr);
+	sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len);
+	if (sstatus != PJ_SUCCESS)
+	    return -44;
+	g_server.port = pj_sockaddr_in_get_port(&addr);
+	pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
+			 "http://127.0.0.1:%d/test/test2.txt",
+			 g_server.port);
+	url = pj_str(urlbuf);
+    }
 
     sstatus = pj_sock_listen(g_server.sock, 8);
@@ -660,4 +709,5 @@
     pj_http_req_callback hcb;
     pj_http_req_param param;
+    char urlbuf[80];
 
     pj_bzero(&hcb, sizeof(hcb));
@@ -673,10 +723,8 @@
 
 #ifdef USE_LOCAL_SERVER
-    pj_cstr(&url, "http://127.0.0.1:380/test/test2.txt");
     thread_quit = PJ_FALSE;
     g_server.action = ACTION_REPLY;
     g_server.send_content_length = PJ_TRUE;
     g_server.data_size = 0;
-    g_server.port = 380;
     g_server.buf_size = 1024;
 
@@ -686,9 +734,22 @@
         return -41;
 
-    pj_sockaddr_in_init(&addr, NULL, (pj_uint16_t)g_server.port);
+    pj_sockaddr_in_init(&addr, NULL, 0);
 
     sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr));
     if (sstatus != PJ_SUCCESS)
         return -43;
+
+    {
+	pj_sockaddr_in addr;
+	int addr_len = sizeof(addr);
+	sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len);
+	if (sstatus != PJ_SUCCESS)
+	    return -44;
+	g_server.port = pj_sockaddr_in_get_port(&addr);
+	pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
+			 "http://127.0.0.1:%d/test/test2.txt",
+			 g_server.port);
+	url = pj_str(urlbuf);
+    }
 
     sstatus = pj_sock_listen(g_server.sock, 8);
