From 3fadb77395e7df8670a83d688f393a67ed81cf4a Mon Sep 17 00:00:00 2001 From: Ferràn Quer i Guerrero Date: Thu, 8 May 2014 08:17:16 +0000 Subject: [PATCH] --- Project/applications/smartcities/httpClient.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Project/applications/smartcities/httpClient.c b/Project/applications/smartcities/httpClient.c index a8c8f1a..cc2a53d 100644 --- a/Project/applications/smartcities/httpClient.c +++ b/Project/applications/smartcities/httpClient.c @@ -18,6 +18,8 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) char* request; char* response; + + err_t connection_ok = -1; ip4_addr_set_u32(&remote_ip,ipaddr_addr(SERVER_IP)); @@ -87,20 +89,22 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/ netconn_connect(neocon, &remote_ip, DEFAULT_REMOTE_PORT); - // Send Request - printf("httpRequest: Sending request\r\n"); - netconn_write(neocon, request, request_size, NETCONN_NOCOPY); - chHeapFree(request); - - // Wait for Response - printf("httpRequest: Waiting for response\r\n"); - //neocon->recv_timeout = 5000; // for 5s - err_t res=netconn_recv(neocon, &netBufs); - printf("res recv= %d\r\n",res); + while(connection_ok !=0) // != ERR_OK + { + // Send Request + printf("httpRequest: Sending request\r\n"); + netconn_write(neocon, request, request_size, NETCONN_NOCOPY); + chHeapFree(request); + + // Wait for Response + printf("httpRequest: Waiting for response\r\n"); + //neocon->recv_timeout = 5000; // for 5s + connection_ok = netconn_recv(neocon, &netBufs); + printf("res recv= %d\r\n",connection_ok); + } // Manage Response printf("httpRequest: Response received. Let's parse the information\r\n"); response = (char*)chHeapAlloc(NULL,4*sizeof(char)); - printf("gggg\r\n"); netbuf_copy_partial(netBufs,response,3,9); // read 3B starting from 9th -> read response code. "HTTP/1.1 301 Moved Permanently" printf("httpRequest: Unbelievablelybilbiyblyib successful! :D\r\nResponse code: %s\r\n",response); int http_response = response2int(response); -- libgit2 0.22.2