From 106ecd02516f7877349cc5e90319087876c0e239 Mon Sep 17 00:00:00 2001 From: Ferràn Quer i Guerrero Date: Tue, 25 Mar 2014 11:47:28 +0000 Subject: [PATCH] --- Project/applications/smartcities/Makefile | 2 +- Project/applications/smartcities/httpClient.c | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Project/applications/smartcities/Makefile b/Project/applications/smartcities/Makefile index c941730..dbe0409 100644 --- a/Project/applications/smartcities/Makefile +++ b/Project/applications/smartcities/Makefile @@ -10,7 +10,7 @@ SDK_ROOT = ../../ PROJECT_OUT = smartcities -USER_SRC = main.c +USER_SRC = main.c USER_INCDIR = include/ # if you need to add build Defines options add to USER_DEFS define diff --git a/Project/applications/smartcities/httpClient.c b/Project/applications/smartcities/httpClient.c index 6fcdd97..3a7ce5d 100644 --- a/Project/applications/smartcities/httpClient.c +++ b/Project/applications/smartcities/httpClient.c @@ -21,12 +21,14 @@ char* response; int httpRequest(struct httpHeaders head, struct ip_addr remote_ip, u16_t remote_port, char* content, int content_size) { // Check or default params + printf("httpRequest: Checking params\r\n"); if (head.uri == NULL || content == NULL) return 1; if (head.host == NULL) continue; //head.host = DEFAULT_REMOTE_PORT; if (remote_ip == NULL || remote_ip == 0) remote_ip = DEFAULT_REMOTE_IP; if (remote_port == NULL || remote_port == 0) remote_port = DEFAULT_REMOTE_PORT; // Calculate header size + printf("httpRequest: Calculating header size\r\n"); int head_size = strlen(reqMethod2text(head.method)); head_size += sizeof " " + head.uri_size + sizeof " HTTP/1.1" + sizeof ENDL; head_size += sizeof "Host: " + head.host_size + sizeof ENDL; @@ -35,6 +37,7 @@ int httpRequest(struct httpHeaders head, struct ip_addr remote_ip, u16_t remote_ head_size += sizeof "Content-Length: " + numberofdigits(content_size) + 2*(sizeof ENDL) + sizeof '\0'; // Build request head + printf("httpRequest: Building request head\r\n"); int request_size = head_size + content_size + 2*(sizeof ENDL) + sizeof '\0'; request = (char *) malloc(request_size); strcpy(request, reqMethod2text(method)); @@ -54,24 +57,30 @@ int httpRequest(struct httpHeaders head, struct ip_addr remote_ip, u16_t remote_ strcat(request, ENDL); // Build request with content + printf("httpRequest: Adding content to request string\r\n"); strcat(request, content); // Set connection + printf("httpRequest: Setting connection\r\n"); neocon = netconn_new(NETCONN_TCP); /*local_ip.addr = 0;//getip netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/ netconn_connect(neocon, &remote_ip, remote_port); // Send Request + printf("httpRequest: Sending request\r\n"); netconn_write(neocon, request, request_size, NETCONN_NOCOPY); // Wait for Response + printf("httpRequest: Waiting for response\r\n"); neocon->recv_timeout = 5000; // for 5s netconn_recv(neocon, netBufs); // Manage Response + printf("httpRequest: Response received. Let's parse the information\r\n"); response = (char*)malloc(4*sizeof char); netbuf_copy(netBuf,response,3,9); // read 3B starting from 9th -> read response code. "HTTP/1.1 301 Moved Permanently" + printf("httpRequest: Unbelievablelybilbiyblyib successful! :D\r\n"); return response2int(response); } -- libgit2 0.22.2