AnsweredAssumed Answered

LWIP send data

Question asked by zavodny.vilem on Mar 18, 2014
Latest reply on Jul 25, 2016 by kumar.sanjay.005
Hi,
I use LWIP and FreeRTOS like WEB server. It's OK. But now, I want send data to otger page for example by GET. Like this: http://www.page.com/p.php?json=1234

Can you help me please?
Here is my code:

01.portCHAR PAGE_BODY[512];
02.  struct netconn *conn1 = NULL;
03. 
04.    struct ip_addr local_ip;
05.    struct ip_addr remote_ip;
06.    int rc1, rc2;
07.   
08.    strcat((char *) PAGE_BODY, "HTTP/1.0 ");
09.    strcat((char *) PAGE_BODY, "Method: POST\r\n");
10.    strcat((char *) PAGE_BODY, "Server: Ethernet termostat\r\n");
11.    strcat((char *) PAGE_BODY, "Content-Length: 9\r\n");
12.    strcat((char *) PAGE_BODY, "json=1234\r\n\r\n");
13.    strcat((char *) PAGE_BODY, "Content-type: application/x-www-form-urlencoded\n\n");
14.     
15.     
16.  /* Create a new TCP connection handle */
17.  conn1 = netconn_new(NETCONN_TCP);
18.   
19.  if (conn1!= NULL)
20.  {
21.    local_ip.addr = NULL;
22.        rc1 = netconn_bind ( conn1, &local_ip, 0 );
23.        IP4_ADDR(&remote_ip,  46, 28,   105, 62);
24.    //remote_ip.addr = remote_ip; // static or by netconn_gethostbyname ()
25.        rc2 = netconn_connect ( conn1, &remote_ip, 80 );
26.          
27.        if ( rc1 != ERR_OK || rc2 != ERR_OK )
28.        {
29.             
30.            netconn_write(conn1, PAGE_BODY, strlen(PAGE_BODY), NETCONN_COPY);
31.            netconn_delete ( conn1 );
32.        }
33.  }
34.  else
35.  {
36.    printf("can not create netconn");
37.  }

Outcomes