Post data HTTP

I know there are several topic about this subject, I read them but couldn’t find an answer yet.
I try to post some data to a php script on my server. Using FXT009 (FW 7.46, WIP 5.42)

On one server I get a 200 OK message, but the data I try to post is somehow not posted. I can get some data from the url with php, but php tells me there are 0 posts in the message. It doesn’t matters if I add the Content-Length header to this one.

If I try to post something to my other server I get a 411 message Content-Length required, while I have a header Length-content added to the HTTP Post.

I played something with the options like HTTP 1.0, but that won’t work either. I get messages like not authorized and couldn’t find save.php :open_mouth:

static s32 http_ClientCreate(wip_bearer_t Br_Id)
   s32 ret = 0;
   char *ip = disp_ip(Br_Id);

   char conlen[3];
   ascii url[50];

   adl_atSendResponse ( ADL_AT_UNS, conlen);
   TRACE(( 1, "CONLEN = %03d",strlen(Data_Send)+1));

   // HTTP Session creation
   http_ClientCtx.HttpCnxCh = wip_HTTPClientCreateOpts(
         WIP_COPT_HTTP_HEADER, "User-Agent", "WIPHTTP/1.1",
   if (http_ClientCtx.HttpCnxCh == NULL)
      TRACE(( 1, "Cannot create HTTP session channel\n" ));
      ret = -1;
      // HTTP POST command
      http_ClientCtx.HttpDataCh = wip_getFileOpts(
            WIP_COPT_HTTP_HEADER, "Accept", "text/html",
            WIP_COPT_HTTP_HEADER, "Content-Length", conlen,
            WIP_COPT_HTTP_HEADER, "Content-Type", "application/x-www-form-urlencoded",
      if (http_ClientCtx.HttpDataCh == NULL)
         TRACE(( 1, "Cannot create http data channel" ));
         wip_close( http_ClientCtx.HttpCnxCh);
         ret =-1;
    	  TRACE(( 1, "Created HTTP data channel" ));


		TRACE((1,"CEV write data:"));

		BytesWritten = wip_write( http_ClientCtx.HttpDataCh, Data_Send, (strlen(Data_Send)+1)-Sent_Bytes);
		if(BytesWritten < 0){
			TRACE((1,"Error sending data :("));

		Sent_Bytes += BytesWritten; // Update the number of bytes sent.

		if( Sent_Bytes == strlen(Data_Send)+1){ // All data sent
			TRACE((1,"HttpDataHandler: All data send"));

		if(wip_shutdown( http_ClientCtx.HttpDataCh,FALSE,TRUE)==0){
			TRACE((1,"wip_shutdown error"));


2012/03/09;10:22:42:431;001;ADL;1;Bear ip connected
2012/03/09;10:22:42:434;001;ADL;1;CONLEN = 042
2012/03/09;10:22:42:438;001;ADL;1;Created HTTP data channel
2012/03/09;10:22:43:326;001;ADL;1;Cev open
2012/03/09;10:22:43:331;001;ADL;1;CEV write data:
2012/03/09;10:22:43:344;001;ADL;1;HttpDataHandler: All data send
2012/03/09;10:22:44:541;001;ADL;1;Cev read
2012/03/09;10:22:44:547;001;ADL;1;HttpDataHandler: read 174 bytes<LF>
2012/03/09;10:22:44:559;001;ADL;1;HttpDataHandler: WIP_CEV_PEER_CLOSE<LF>
2012/03/09;10:22:44:573;001;ADL;1;HTTP Error :(
2012/03/09;10:22:44:577;001;ADL;1;HttpDataHandler: Status=411<LF>
2012/03/09;10:22:44:583;001;ADL;4;HttpDataHandler: Reason="Length Required"<LF>
2012/03/09;10:22:44:588;001;ADL;1;HttpDataHandler: Content Type="text/html"<LF>
2012/03/09;10:22:44:593;001;ADL;1;HttpDataHandler: Response Length=174 bytes<LF>
2012/03/09;10:22:44:596;001;ADL;1;Cev Close

I hope there is somehow a solution for this. I tried to post data to save.php via a browser, then everything works so it seems my php script is ok. I don’t know how to sniff the HTTP packet which comes from the fxt009, otherwise I could check the contents and if there is something wrong with it.

The wip library will upload the POST as chuncked encoded. There is therefore no reason at all to add the content-length. Most likely, the server simply doesn’t accept chunked POST’s. To workaround:

  • don’t use POST’s
  • don’t use wip, but a HTTP client which support content-length POST’s.
  • change your server to accept chuncked transfered POST requests.

don´t just check the Post-Vars ($_POST[‘var’] in php), also check the InputStream

Aha OK Thnx for the replies, I thought my server can receive chunked data. Is it possible it can receive chunked data but no chunked posts? I’ll look into changing my server but so far I couldn’t find the possibility to change it :slight_smile:
I’ll also look into the InputStream…

One other question is it possible to initiate a request from the server side to the FXT009, for instance I want to do a POST HTTP request with some variables so the FXT009 will send these variables through via UART2.
While after a HTTP request from the FXT009 to the server, the connection is closed isn’t it? Or is there another option to do this with the wip library?

if you are using gprs (or better…) it depends on your contract with the provider ;>
but most likely you are behind a NAT system and opening a connection from the server to the module is… tricky…

but if i got you right and the connection between server and module is via uart… why shouldnt it go?

Ok yes currently in the developing state we are behind a NAT, but in the future we will have our own E-VPN.
But is it possible with the HTTP client and a keep alive connection or something? Or should there be something build on top of a TCP server in the FXT009? Or is is just sending a HTTP request to the IP and port 80 or something like that?

if you want to stay at HTTP, the “easiest” way would be to poll the server, since the connection ends after the Server sends the answer.
you might use long polling instead of short polling, to “simulate” the connection - if your server is capable of doing so :smiley:

if you want a constant tcp connection between server and modul, the modul would have to open the connection to the server.
otherwise you would have to use some kind of NAT-Traversal… but even then the modul would need to know, when it has to start the process… which brings you back to “the modul has to do…”

Ok, I was already scared that it would have to be such a solution. In terms of data limit polling the server is no option. I have some other solution which I tested. It is not the most beautiful solution, but currently I created a TCP server in the FXT009. If I have some data at my server I try to make a TCP connection which starts a HTTP client in the FXT009 to my server. In the response to the HTTP request I will put the data I wanted to send to the FXT009…


Sorry I meant reduction of the amount of data flowing, if I will be polling the connection it has to send a HTTP packet every amount of time isn’t it… That generates a lot of data flowing…

oehm… not at all…
lets say each poll request is 500 bytes (should be less… but its a n1 number^^)
lets say you are polling 24/7
lets say your modul can poll as fast as my modul can (sl 6087) (1 request every 1.3 seconds)

that is… 500 byte * 24 * 60 * 60 / 1.3… thats round a bout 31,6MByte per Day… or 982MByte per month…
if you are polling the entire time, which you are probably not going to do…

Yes that’s what I meant, they want the data to be something like 1MB per month :wink:. So polling is no option, because it generates a lot of data usage :slight_smile:

I created this project to solve this. I will hang on the socket waiting for commands. Commands can be send from javascript (node.js) and all other languages supports. It does use a third party though.