Commit 106ecd02516f7877349cc5e90319087876c0e239
1 parent
5fc47ae3
--no commit message
Showing
2 changed files
with
10 additions
and
1 deletions
Project/applications/smartcities/Makefile
Project/applications/smartcities/httpClient.c
... | ... | @@ -21,12 +21,14 @@ char* response; |
21 | 21 | int httpRequest(struct httpHeaders head, struct ip_addr remote_ip, u16_t remote_port, char* content, int content_size) |
22 | 22 | { |
23 | 23 | // Check or default params |
24 | + printf("httpRequest: Checking params\r\n"); | |
24 | 25 | if (head.uri == NULL || content == NULL) return 1; |
25 | 26 | if (head.host == NULL) continue; //head.host = DEFAULT_REMOTE_PORT; |
26 | 27 | if (remote_ip == NULL || remote_ip == 0) remote_ip = DEFAULT_REMOTE_IP; |
27 | 28 | if (remote_port == NULL || remote_port == 0) remote_port = DEFAULT_REMOTE_PORT; |
28 | 29 | |
29 | 30 | // Calculate header size |
31 | + printf("httpRequest: Calculating header size\r\n"); | |
30 | 32 | int head_size = strlen(reqMethod2text(head.method)); |
31 | 33 | head_size += sizeof " " + head.uri_size + sizeof " HTTP/1.1" + sizeof ENDL; |
32 | 34 | 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_ |
35 | 37 | head_size += sizeof "Content-Length: " + numberofdigits(content_size) + 2*(sizeof ENDL) + sizeof '\0'; |
36 | 38 | |
37 | 39 | // Build request head |
40 | + printf("httpRequest: Building request head\r\n"); | |
38 | 41 | int request_size = head_size + content_size + 2*(sizeof ENDL) + sizeof '\0'; |
39 | 42 | request = (char *) malloc(request_size); |
40 | 43 | strcpy(request, reqMethod2text(method)); |
... | ... | @@ -54,24 +57,30 @@ int httpRequest(struct httpHeaders head, struct ip_addr remote_ip, u16_t remote_ |
54 | 57 | strcat(request, ENDL); |
55 | 58 | |
56 | 59 | // Build request with content |
60 | + printf("httpRequest: Adding content to request string\r\n"); | |
57 | 61 | strcat(request, content); |
58 | 62 | |
59 | 63 | // Set connection |
64 | + printf("httpRequest: Setting connection\r\n"); | |
60 | 65 | neocon = netconn_new(NETCONN_TCP); |
61 | 66 | /*local_ip.addr = 0;//getip |
62 | 67 | netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/ |
63 | 68 | netconn_connect(neocon, &remote_ip, remote_port); |
64 | 69 | |
65 | 70 | // Send Request |
71 | + printf("httpRequest: Sending request\r\n"); | |
66 | 72 | netconn_write(neocon, request, request_size, NETCONN_NOCOPY); |
67 | 73 | |
68 | 74 | // Wait for Response |
75 | + printf("httpRequest: Waiting for response\r\n"); | |
69 | 76 | neocon->recv_timeout = 5000; // for 5s |
70 | 77 | netconn_recv(neocon, netBufs); |
71 | 78 | |
72 | 79 | // Manage Response |
80 | + printf("httpRequest: Response received. Let's parse the information\r\n"); | |
73 | 81 | response = (char*)malloc(4*sizeof char); |
74 | 82 | netbuf_copy(netBuf,response,3,9); // read 3B starting from 9th -> read response code. "HTTP/1.1 301 Moved Permanently" |
83 | + printf("httpRequest: Unbelievablelybilbiyblyib successful! :D\r\n"); | |
75 | 84 | return response2int(response); |
76 | 85 | } |
77 | 86 | ... | ... |