Problem with WIP_CEV_WRITE event in WIP_HTTP_METHOD_GET

Hi all,
i’m having a problem with Q2686. I’m trying to send some data to a server (page: get_data.php) using the code in http_get example of WIP plugin 5.10. the TRACE i get is

+CREG: 2
+WIND: 16
+WIND: 15,1,“WIND GR”,2,“WIND GR”,4,“09/03/17,10:34:07+08”,6,“0”
+CREG: 1,“2774”,“2879”
GPRS: open: -> DISCONNECTED
GPRS: start: -> CONNECTING
+WIND: 4
+WIND: 10,“SM”,1,“FD”,0,“ON”,0,“SN”,0,“EN”,0
+WIND: 11,“BFE469158A1FA7A9BFC705F5FF249CE5”,“EAA8E28603036F65613827F8A1113490”,“23E937146F29BD314A463EBCB1ADC223”
GPRS: GPRS EVENT SETUP OK (cid=1): GPRS activate
GPRS: GPRS EVENT: 27 (cid=1)
+WIND: 15,1,"WIND GR ",2,“WIND GR “,3,”+08”,4,“09/03/17,10:34:14+08”,6,“0”
GPRS: GPRS EVENT ACTIVATE OK (cid=5): FCM open
GPRS: FCM subscribe: 0
GPRS: FCM EVENT FLOW OPENNED: -> CONNECTED
HTTP Client Service test application : Init
[HTTP] new request xx.xx.xx/get_data.php?message= @ 00485940
[HTTP] connect to host: xx.xx.xx:80
[HTTP] channel = 00485b40
[WIPEV] WIP_CEV_OPEN @ 0x485b40
[WIPEV] WIP_CEV_WRITE @ 0x485b40 (5840 bytes)
[WIPEV] WIP_CEV_OPEN @ 0x485940
http_ClientTestDataHandler: Start
[WIPEV] WIP_CEV_READ @ 0x485b40 (315 bytes)
[WIPEV] WIP_CEV_READ @ 0x485b40 (299 bytes)
[WIPEV] WIP_CEV_READ @ 0x485940 (0 bytes)

Untitled Document [WIPEV] WIP_CEV_READ @ 0x485b40 (5 bytes) [WIPEV] WIP_CEV_PEER_CLOSE @ 0x485b40 [HTTP] channel closed by server [WIPEV] WIP_CEV_PEER_CLOSE @ 0x485940 http_ClientTestDataHandler: Done http_ClientTestDataHandler: Status=200 http_ClientTestDataHandler: Reason="OK"

and then nothing happens. I cannot get the WIP_CEV_WRITE event so that data will be transmitted to the server because the server closes the channel.

Has anyone any idea what’s wrong and why this happens?
Thanks in advance

I’ve changed some things in my code and now the traces i get are:
[GPRS]: initialized.
[GSM]: initialized.
[UART1]: initialized.
[UART2]: initialized.
[]: initialized.
[GPRS]: open: -> DISCONNECTED
[GPRS]: start: -> CONNECTING
[GPRS]: GPRS EVENT SETUP OK (cid=1): GPRS activate
[GPRS]: GPRS EVENT: 27 (cid=1)
[GPRS]: GPRS EVENT ACTIVATE OK (cid=5): FCM open
[GPRS]: FCM subscribe: 0
[GPRS]: FCM EVENT FLOW OPENNED: -> CONNECTED
HTTP Client Service test application : Init
[HTTP] new request GET xxx.xxx/xxx/get_data.php HTTP/1.1 @ 00485fa0
[HTTP] connect to host: www.xxx.xxx:80
http_ClientTestDataHandler: Start
http_ClientTestDataHandler: WIP_CEV_WRITE
message=35998300065115220090319144625fs0.0331, -0.0647, 0.0331, -0.0647, -0.0647, 0.0331, -0.0647, -0.0647, -0.0647, 0.1187, -0.0647, -0.0647, 0.0331, 0.0331, -0.0647, 0.4978, 0.4978, -0.0647,ff,000000000000000
wip_write ret: 210
[HTTP] error -987 @ 00485fa0
[HTTP] channel closed by server
http_ClientTestDataHandler: ERROR
[WIP] closing TCPCLIENT 0x486220
[WIP] closing HTTP_DATA 0x485fa0

Although i check the state of the connection channel and i get WIP_CSTATE_READY then i get 987 error.
Please can anyone help me??

Hiya,

A couple of observations:

  1. You cannot write data to a http server using GET request. Use a POST request instead.
  2. With a POST request, the data is sent to the server FIRST, so you will get the WRITE event before the READ event
  3. You have to close the WRITE channel after finishing the write event. If you don’t close the WRITE channel, you will never get the READ event.

Check out HTTP Made Realy Easy for a good primer on writing a HTTP client (which is what you are doing).

ciao, Dave

EDIT: You cannot write MUCH data using the GET request - it depends on the http server.

I thoroughly endorse that recommendation!

And the associated Sockets Tutorial - available in both MS Windows and BSD versions.

You are so wright to make these comments because I have not posted the code.
so here it is.

static void http_ClientTestDataHandler( wip_event_t *ev, void *ctx)
{
  ascii tmpbuf[256];
  int len, tmplen;
  s32 status;
  http_ClientTestCtx_t *pHttpClientCtx =
    (http_ClientTestCtx_t *) &http_ClientTestCtx;
s16 retWrite = 0;
  char sending[1500];
  char string[100];
	  s32 ret = 0;
	  int wrt;
	  s32 code;

  switch(ev->kind)
  {
    case WIP_CEV_OPEN:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_OPEN\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Start\r\n" );

      // ready for getting response data
      pHttpClientCtx->dataLength  = 0;

      break;

    case WIP_CEV_READ:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_READ\n" ));

      // we must read all available data to trigger WIP_CEV_READ again
	  wip_getOpts(http_ClientTestCtx.CnxChannel, WIP_COPT_HTTP_STATUS_CODE, &code, WIP_COPT_END);
      
	  TRACE((4, "return code is %d", code));
      tmplen = 0;
      while( (len = wip_read( ev->channel, tmpbuf, sizeof(tmpbuf)-1)) > 0) {
        tmpbuf[len] = 0;
        adl_atSendResponse ( ADL_AT_UNS, tmpbuf );
        tmplen += len;
      }
      TRACE(( 4, "http_ClientTestDataHandler: read %d bytes\n", tmplen ));
      // compute total length of response
      pHttpClientCtx->dataLength += len;
      break;

    case WIP_CEV_PEER_CLOSE:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_PEER_CLOSE\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Done\r\n" );
      // end of data
      // show response information
      if( wip_getOpts( ev->channel, WIP_COPT_HTTP_STATUS_CODE, &status, WIP_COPT_HTTP_STATUS_REASON, tmpbuf, sizeof(tmpbuf),WIP_COPT_END) == OK)
	  {
        ascii sbuf[16];
        adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Status=" );
        wm_sprintf( sbuf, "%d", status);
        adl_atSendResponse ( ADL_AT_UNS, sbuf);
        adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Reason=\"" );
        adl_atSendResponse ( ADL_AT_UNS, tmpbuf);
        adl_atSendResponse ( ADL_AT_UNS, "\"\r\n" );
        TRACE(( 4, "http_ClientTestDataHandler: Status=%d\n", status));
        TRACE(( 4, "http_ClientTestDataHandler: Reason=\"%s\"\n", tmpbuf));
      }
      if( wip_getOpts( ev->channel,WIP_COPT_HTTP_HEADER, "content-type", tmpbuf, sizeof(tmpbuf),WIP_COPT_END) == OK) 
	  {
        TRACE(( 4, "http_ClientTestDataHandler: Content Type=\"%s\"\n", tmpbuf));
      }          
      TRACE(( 4, "http_ClientTestDataHandler: Response Length=%d bytes\n",pHttpClientCtx->dataLength ));
      // data channel must be closed
      wip_close( ev->channel);

      break;
	case WIP_CEV_WRITE:
		wip_state = wip_getState(http_ClientTestCtx.CnxChannel);
		if (wip_state==WIP_CSTATE_READY)
		{
			adl_atSendResponse ( ADL_AT_UNS, "\r\n http_ClientTestDataHandler: WIP_CEV_WRITE\r\n" );
			wrt = wm_strlen(sending);
			// Write POST argument to HTTP request
			retWrite = wip_write(http_ClientTestCtx.DataChannel, sending, wrt);
			wm_sprintf(string, "%s\r\n", sending);
			SEND_TRACE(string);
			string[0]='\0';
			wm_sprintf(string, "wip_write ret: %d\r\n", retWrite);
			SEND_TRACE(string);
			string[0]='\0';
			ret=wip_shutdown(http_ClientTestCtx.DataChannel/*ev->channel*/, FALSE, TRUE);
		}
		break;

    case WIP_CEV_ERROR:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_ERROR %d\n",
              ev->content.error.errnum));
      adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: ERROR\r\n" );
      wip_close( ev->channel);

      break;

    default:
      TRACE(( 4, "http_ClientTestDataHandler: unexpected event: %d\n",
              ev->kind));
      break;
  }
}


static s32 http_ClientTestCreate(void)
{
  s32 ret = 0;
  const ascii * HTTP_STR_URL = "http://xxx.xxx.xxx/get_data.php";
   // HTTP Session creation
  // ---------------------------
  http_ClientTestCtx.CnxChannel = wip_HTTPClientCreateOpts(
                    NULL,  // no handler
                    NULL,  // no context    
                    WIP_COPT_HTTP_HEADER, "User-Agent", "WIPHTTP/1.0",    
                    WIP_COPT_END);

  if (http_ClientTestCtx.CnxChannel == NULL)
  {
    TRACE(( 1, "cannot create http session channel\n" ));
    adl_atSendResponse ( ADL_AT_UNS, "cannot create http session channel\r\n" );
    ret = -1;
  }
  else
  {
    // HTTP GET command
    // ---------------------------
    http_ClientTestCtx.DataChannel = wip_getFileOpts(
                        http_ClientTestCtx.CnxChannel,  // session channel                       
                        HTTP_STR_URL,                   // requested URL                       
                        http_ClientTestDataHandler,     // data handler
                        //&http_ClientTestCtx,            // context
                        NULL,
                        WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,
                        WIP_COPT_HTTP_HEADER, "Accept", "*",                                             
                        WIP_COPT_END);

    if (http_ClientTestCtx.DataChannel == NULL)
    {
      TRACE(( 1, "cannot create http data channel\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "cannot create http data channel\r\n" );
      wip_close( http_ClientTestCtx.CnxChannel);
      ret =-1;
    }
  }

  return(ret);
}

And i get the traces i posted above.
So what do you thing is wrong. Why the server closes the connection? Or is it something else that causes this reaction?

Hiya,

error -987 is WIP_CERR_PIPE_BROKEN (see the WIP manual, section 16.3)

This is not a valid POST request, so the HTTP server is probably getting upset and aborting the connection (as they are supposed to do).

Read the section The POST Method in reference I posted before on how to create/format a valid POST request.

ciao, Dave

Now i post something like that
message=35998300065115220090319144625fsA0.0331E0.0647A0.0331E0.0647E0.0647A0.0331E0.0647E0.0647E0.0647A0.1187E0.0647E0.0647A0.0331A0.0331
E0.0647A0.4978A0.4978E0.0647ff000000000000000

but the error message is the same -987 channel closed by server

Any ideas?

Hiya,

Have you checked the error (and access) logs on your web server? If you are running Apache, you should get some sort of meaningful message in the logs about why the server closed the connection.

ciao, Dave

Server has the following logs
212.152.116.77 - - [17/Mar/2009:04:50:02 -0500] “GET /get_data.php?message= HTTP/1.1” 200 1451 “-” “WIPHTTP/1.0”

but the connection closes again even if I get 200 code.

I can’t understand a thing

Hiya,

My apache server has the following log entry whenever I do a POST upload:

58.171.54.165 - - [26/Mar/2009:12:54:35 +1000] "POST /upload.php HTTP/1.1" 200 -

This looks like you are still using a GET connection to the server - although perusing the code you posted indicates that you are using the POST method.

Don’t forget that HTTP is a stateless transaction - default is one request gets one response, then the server closes the connection (although there are other modes that keep the socket open and pipeline transactions).

Do yourself a favour and try the following:

Install XAMPP on your local windows box (or a local copy of Apache if you are developing using linux).

Use the PuTTY terminal client (in RAW mode) to connect to port 80 of your local web server. Simulate a HTTP client by typing in the headers etc and then your data and see what happens on the console. You will then be able to see just what is being returned by your PHP script, and what responses the web server returns to the screen.

Check out the reference I posted before on what headers etc are required and how to format a HTTP request.

Also, in PuTTY, set the ‘Always close window on exit’ to Never so the window doesn’t automatically close when the connection is closed…

Let us know how you get on.

ciao, Dave

Another tool for debugging HTTP is Fiddler: fiddler2.com/fiddler2/

It also lets you manually create requests, and see all the responses…

Hiya,

Thanks for that - I hadn’t seen it before. It’s downloading as I type.

I’ve just gotten very used to using command line tools to do things - have been burnt a number of times by GUI tools that do almost everything that’s needed…

ciao, Dave

Hi to all,
I swear, davidc, my code is this one

static void http_ClientTestDataHandler( wip_event_t *ev, void *ctx)
{
  ascii tmpbuf[256];
  int len, tmplen;
  s32 status;
  http_ClientTestCtx_t *pHttpClientCtx =
    (http_ClientTestCtx_t *) &http_ClientTestCtx;
s16 retWrite = 0;
	  //char undash=%2D";
	  s32 ret = 0;
	  
	  s32 code;

  switch(ev->kind)
  {
    case WIP_CEV_OPEN:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_OPEN\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Start\r\n" );

      // ready for getting response data
      pHttpClientCtx->dataLength  = 0;

      break;

    case WIP_CEV_READ:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_READ\n" ));

      // we must read all available data to trigger WIP_CEV_READ again
	  wip_getOpts(http_ClientTestCtx.CnxChannel, WIP_COPT_HTTP_STATUS_CODE, &code, WIP_COPT_END);
      
	  TRACE((4, "return code is %d", code));
      tmplen = 0;
      while( (len = wip_read( ev->channel, tmpbuf, sizeof(tmpbuf)-1)) > 0) {
        tmpbuf[len] = 0;
        adl_atSendResponse ( ADL_AT_UNS, tmpbuf );
        tmplen += len;
      }
      TRACE(( 4, "http_ClientTestDataHandler: read %d bytes\n", tmplen ));
      // compute total length of response
      pHttpClientCtx->dataLength += len;
      break;

    case WIP_CEV_PEER_CLOSE:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_PEER_CLOSE\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Done\r\n" );
      // end of data
      // show response information
      if( wip_getOpts( ev->channel, WIP_COPT_HTTP_STATUS_CODE, &status, WIP_COPT_HTTP_STATUS_REASON, tmpbuf, sizeof(tmpbuf),WIP_COPT_END) == OK)
	  {
        ascii sbuf[16];
        adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Status=" );
        wm_sprintf( sbuf, "%d", status);
        adl_atSendResponse ( ADL_AT_UNS, sbuf);
        adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Reason=\"" );
        adl_atSendResponse ( ADL_AT_UNS, tmpbuf);
        adl_atSendResponse ( ADL_AT_UNS, "\"\r\n" );
        TRACE(( 4, "http_ClientTestDataHandler: Status=%d\n", status));
        TRACE(( 4, "http_ClientTestDataHandler: Reason=\"%s\"\n", tmpbuf));
      }
      if( wip_getOpts( ev->channel,WIP_COPT_HTTP_HEADER, "content-type", tmpbuf, sizeof(tmpbuf),WIP_COPT_END) == OK) 
	  {
        TRACE(( 4, "http_ClientTestDataHandler: Content Type=\"%s\"\n", tmpbuf));
      }          
      TRACE(( 4, "http_ClientTestDataHandler: Response Length=%d bytes\n",pHttpClientCtx->dataLength ));

      // data channel must be closed
      wip_close( ev->channel);

      break;
	case WIP_CEV_WRITE:
		wip_state = wip_getState(http_ClientTestCtx.CnxChannel);
		if (wip_state==WIP_CSTATE_READY)
		{		
			adl_atSendResponse ( ADL_AT_UNS, "\r\n http_ClientTestDataHandler: WIP_CEV_WRITE\r\n" );
			
			retWrite = wip_write(http_ClientTestCtx.DataChannel, sending, wrt);
			adl_atSendResponse(ADL_AT_UNS, sending);
			ret=wip_shutdown(http_ClientTestCtx.DataChannel/*ev->channel*/, FALSE, TRUE);
		}
		break;

    case WIP_CEV_ERROR:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_ERROR %d\n",
              ev->content.error.errnum));
      adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: ERROR\r\n" );

      // connection to server broken
      wip_close( ev->channel);

      break;

    default:
      TRACE(( 4, "http_ClientTestDataHandler: unexpected event: %d\n",
              ev->kind));
      break;
  }
}

/***************************************************************************/
/*  Function   : http_ClientTestCreate                                     */
/*-------------------------------------------------------------------------*/
/*  Object     : HTTP get example                                          */
/*                                                                         */
/*  Returned   : none                                                      */
/*                                                                       */
/*--------------------+---+---+---+----------------------------------------*/
/* Variable Name      |IN |OUT|GLB| Use                                    */
/*--------------------+---+---+---+----------------------------------------*/
/*                    |   |   |   |                                        */
/***************************************************************************/
static s32 http_ClientTestCreate(void)
{
  s32 ret = 0;
  char buffer[4];

  const ascii * HTTP_STR_URL = "http://xxx.xxx.xxx/get_data.php";
   sprintf(buffer, "%d", wrt);
   // HTTP Session creation
  // ---------------------------
  http_ClientTestCtx.CnxChannel = wip_HTTPClientCreateOpts(
                    NULL,  // no handler
                    NULL,  // no context    
                    // default headers
                    //WIP_COPT_HTTP_HEADER, "User-Agent", "WIP-HTTP-Client/1.0",    
					WIP_COPT_HTTP_HEADER, "User-Agent", "HTTP/1.1 100 Continue",
                    WIP_COPT_END);

  if (http_ClientTestCtx.CnxChannel == NULL)
  {
    TRACE(( 1, "cannot create http session channel\n" ));
    adl_atSendResponse ( ADL_AT_UNS, "cannot create http session channel\r\n" );
    ret = -1;
  }
  else
  {
    // HTTP POST command
    // ---------------------------
    http_ClientTestCtx.DataChannel = wip_getFileOpts(
                        http_ClientTestCtx.CnxChannel,  // session channel                       
                        HTTP_STR_URL,                   // requested URL                       
                        http_ClientTestDataHandler,     // data handler
                        //&http_ClientTestCtx,            // context
                        NULL,
                        WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,
						//WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_GET,
                        //WIP_COPT_HTTP_HEADER, "Content-Type", "text/html",                        
                        // request headers
			//WIP_COPT_HTTP_HEADER, "Connection", "Keep-alive",
			//WIP_COPT_HTTP_HEADER, "Content-Length", buffer,
                        WIP_COPT_HTTP_HEADER, "Accept", "*",                                             
                        WIP_COPT_END);

    if (http_ClientTestCtx.DataChannel == NULL)
    {
      TRACE(( 1, "cannot create http data channel\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "cannot create http data channel\r\n" );
      wip_close( http_ClientTestCtx.CnxChannel);
      ret =-1;
    }
  }

  return(ret);
}

and the traces from the microcontroller are
WIND: 7
+CGREG: 0
+CGREG: 0
[GPRS]: initialized.
[GSM]: initialized.
[UART1]: initialized.
[UART2]: initialized.
[]: initialized.
+CREG: 2
+WIND: 16
+WIND: 15,1,“WIND GR”,2,“WIND GR”,4,“09/03/27,11:30:00+08”,6,“0”
+CREG: 1,“2774”,“7699”
[GPRS]: open: -> DISCONNECTED
[GPRS]: start: -> CONNECTING
+WIND: 4
+WIND: 10,“SM”,1,“FD”,0,“ON”,0,“SN”,0,“EN”,0
+WIND: 11,“BFE469158A1FA7A9BFC705F5FF249CE5”,“A649269F8E6894A79D77757D8868ABB9”,“AE457235D0BBCE86461B1879531213D2”
[GPRS]: GPRS EVENT SETUP OK (cid=1): GPRS activate
[GPRS]: GPRS EVENT: 27 (cid=1)

+WIND: 15,1,"WIND GR ",2,“WIND GR “,3,”+08”,4,“09/03/27,11:30:08+08”,6,“0”
[GPRS]: GPRS EVENT ACTIVATE OK (cid=5): FCM open
[GPRS]: FCM subscribe: 0
[GPRS]: FCM EVENT FLOW OPENNED: -> CONNECTED

HTTP Client Service test application : Init
[HTTP] new request GET xxx.xxx.xxx/get_data.php HTTP/1.1 @ 00485fa0
[HTTP] connect to host: xxx.xxx.xxx:80
http_ClientTestDataHandler: Start

http_ClientTestDataHandler: WIP_CEV_WRITE
?message=35998300065115220090327131325fs0.0555,-0.555,ff,000000000000000

411 Length Required

Length Required

A request of the requested method GET requires a valid Content-length.

chunked Transfer-Encoding forbidden: /get_data.php

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

http_ClientTestDataHandler: Done
http_ClientTestDataHandler: Status=411
http_ClientTestDataHandler: Reason=“Length Required”
[WIP] closing HTTP_DATA 0x485fa0
[HTTP] channel closed by server
[WIP] closing TCPCLIENT 0x486220

i cannot figure why in the traces is stated as GET request. I definitely make a post request.
The server has the following log

212.152.122.10 - - [27/Mar/2009:06:30:16 -0500] “POST /get_data.php HTTP/1.1” 411 - “-” “HTTP/1.1 100 Continue”

what’s wrong with the post event I want to make?

Hiya,

I agree that you are using a POST request - and so does the response from the webserver. Looks like there is a quirk in the WIP library debug statements.

I’ve had a look at your headers used in wip_getFileOpts. I use the following headers:

WIP_COPT_HTTP_HEADER, "Accept", "text/html",
WIP_COPT_HTTP_HEADER, "Content-Type", "application/x-www-form-urlencoded",
WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,

I notice that you haven’t set the Content-type header to application/x-www-form-urlencoded. This is required when doing a POST transfer.

The real hint about what’s going wrong is in the error message returned from the server:

Normally, you have to specifiy how many bytes of data you are sending to the server (i.e. use the Content-Length header). More modern servers can also do a chunked transfer - which reads the data in line by line until a blank line is encountered. The wavecom WIP libraries (at least 4 & 5 that I’ve used) support chunked transfer mode.
However, it appears that your server does not support HTTP chunked transfer mode.

Also, it looks to me as though you haven’t URL encoded your POST data - commas and other punctuation need to be URL encoded in your data string.

Some more questions:
What web server are you using? Can you configure it to accept chunked-transfers?

If you can’t configure your web server to acceppt chunked-transfers, you’re going to have to build your message string, URL encode it, then set the Content-Length header with the length of the string that you are transferring. I notice that you have tried this - but you need to do something along the lines of

WIP_COPT_HTTP_HEADER, "Content-Length", wm_strlen(buffer)

Let us know how you get on.

ciao, Dave

See: viewtopic.php?f=16&t=2148&p=7929&hilit=chunked+Transfer+Encoding+forbidden#p7929

Well
i followed your recommendations and i omitted commas in my post, and i added content-length in the header but no luck.
I received, again, the first time -987 error and the second time 411 from the server.

What’s most annoying is that i decided to post my data to the ftp server hoping i would proceed with my problem and post that … data.
No luck at all.
I use wip_ftpcreate() the channel is created with success and then i get:

“Can’t open dst FTP connection
Error 0 on cx channel”

what’s the meaning of 0 error code??
I searched in the manuals but i couldn’t find it.
Have you got any other ideas??

Looks more like internal debug information. I suggest, it would be good if you can contact Wavecom Support. They should be able to provide a solution for your problem.

Hi again.
i tried to send some data that do not contain any punctuation. The errors i get are:
the first time i debug the code (in visual studio)
“[HTTP] error -987 @ 00485fa0
[HTTP] channel closed by server.”
the next times “411 Length Required”
Whenever I restart Visual studio i get the first message, then 411.
the code is

static void http_ClientTestDataHandler( wip_event_t *ev, void *ctx)
{
  ascii tmpbuf[256];
  int len, tmplen;
  s32 status;
  http_ClientTestCtx_t *pHttpClientCtx = (http_ClientTestCtx_t *) &http_ClientTestCtx;
s16 retWrite = 0;
s32 ret = 0;
s32 code;

  switch(ev->kind)
  {
    case WIP_CEV_OPEN:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_OPEN\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Start\r\n" );
      // ready for getting response data
      pHttpClientCtx->dataLength  = 0;
      break;

    case WIP_CEV_READ:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_READ\n" ));
      // we must read all available data to trigger WIP_CEV_READ again
	  wip_getOpts(http_ClientTestCtx.CnxChannel, WIP_COPT_HTTP_STATUS_CODE, &code, WIP_COPT_END);
	  TRACE((4, "return code is %d", code));
      tmplen = 0;
      while( (len = wip_read( ev->channel, tmpbuf, sizeof(tmpbuf)-1)) > 0) {
        tmpbuf[len] = 0;
        adl_atSendResponse ( ADL_AT_UNS, tmpbuf );
        tmplen += len;
      }
      TRACE(( 4, "http_ClientTestDataHandler: read %d bytes\n", tmplen ));
      // compute total length of response
      pHttpClientCtx->dataLength += len;
      break;

    case WIP_CEV_PEER_CLOSE:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_PEER_CLOSE\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Done\r\n" );
      // end of data
      // show response information
      if( wip_getOpts( ev->channel, WIP_COPT_HTTP_STATUS_CODE, &status, WIP_COPT_HTTP_STATUS_REASON, tmpbuf, sizeof(tmpbuf),WIP_COPT_END) == OK)
	  {
        ascii sbuf[16];
        adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: Status=" );
        wm_sprintf( sbuf, "%d", status);
        adl_atSendResponse ( ADL_AT_UNS, sbuf);
        adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: Reason=\"" );
        adl_atSendResponse ( ADL_AT_UNS, tmpbuf);
        adl_atSendResponse ( ADL_AT_UNS, "\"\r\n" );
        TRACE(( 4, "http_ClientTestDataHandler: Status=%d\n", status));
        TRACE(( 4, "http_ClientTestDataHandler: Reason=\"%s\"\n", tmpbuf));
      }
      if( wip_getOpts( ev->channel,WIP_COPT_HTTP_HEADER, "content-type", tmpbuf, sizeof(tmpbuf),WIP_COPT_END) == OK)
	  {
        TRACE(( 4, "http_ClientTestDataHandler: Content Type=\"%s\"\n", tmpbuf));
      }
      TRACE(( 4, "http_ClientTestDataHandler: Response Length=%d bytes\n",pHttpClientCtx->dataLength ));
      // data channel must be closed
      wip_close( ev->channel);
      break;

	case WIP_CEV_WRITE:
		wip_state = wip_getState(http_ClientTestCtx.CnxChannel);
		if (wip_state==WIP_CSTATE_READY)
		{
			adl_atSendResponse ( ADL_AT_UNS, "\r\n http_ClientTestDataHandler: WIP_CEV_WRITE\r\n" );
			retWrite = wip_write(http_ClientTestCtx.DataChannel, sending, wrt);
			adl_atSendResponse(ADL_AT_UNS, sending);
			adl_atSendResponse(ADL_AT_UNS, "\r\n");
			ret=wip_shutdown(http_ClientTestCtx.DataChannel/*ev->channel*/, FALSE, TRUE);
		}
		break;

    case WIP_CEV_ERROR:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_ERROR %d\n",
              ev->content.error.errnum));
      adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: ERROR\r\n" );
      // connection to server broken
      wip_close( ev->channel);
      break;

    default:
      TRACE(( 4, "http_ClientTestDataHandler: unexpected event: %d\n",
              ev->kind));
      break;
  }
}


/***************************************************************************/
/*  Function   : http_ClientTestCreate                                     */
/*-------------------------------------------------------------------------*/
/*  Object     : HTTP get example                                          */
/*                                                                         */
/*  Returned   : none                                                      */
/*                                                                         */
/*                                                                         */
/*--------------------+---+---+---+----------------------------------------*/
/* Variable Name      |IN |OUT|GLB| Use                                    */
/*--------------------+---+---+---+----------------------------------------*/
/*                    |   |   |   |                                        */
/***************************************************************************/
static s32 http_ClientTestCreate(void)
{
  s32 ret = 0;
  char buffer[4];

  const ascii * HTTP_STR_URL = "http://xxx.xxx.xxx/get_data.php";
  //buffer=wm_strlen(wrt); 
  sprintf(buffer, "%d", wrt);
   // HTTP Session creation
  // ---------------------------
  http_ClientTestCtx.CnxChannel = wip_HTTPClientCreateOpts(
                    NULL,  // no handler
                    NULL,  // no context
                    // default headers
                    WIP_COPT_HTTP_HEADER, "User-Agent", "WIPHTTP/1.0",
		//WIP_COPT_HTTP_HEADER, "User-Agent", "HTTP/1.1 100 Continue\r\n",
                    WIP_COPT_END);

  if (http_ClientTestCtx.CnxChannel == NULL)
  {
    TRACE(( 1, "cannot create http session channel\n" ));
    adl_atSendResponse ( ADL_AT_UNS, "cannot create http session channel\r\n" );
    ret = -1;
  }
  else
  {
    // HTTP POST command
    // ---------------------------
    http_ClientTestCtx.DataChannel = wip_getFileOpts(
                        http_ClientTestCtx.CnxChannel,  // session channel
                        HTTP_STR_URL,                   // requested URL
                        http_ClientTestDataHandler,     // data handler
                        //&http_ClientTestCtx,            // context
                        NULL,
						WIP_COPT_HTTP_HEADER, "Accept", "text/html",\
						WIP_COPT_HTTP_HEADER, "Content-Type", "application/x-www-form-urlencoded",
						WIP_COPT_HTTP_HEADER, "Content-Length", buffer,
                        // request headers
						WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,
						//WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_GET,
                        WIP_COPT_END);

    if (http_ClientTestCtx.DataChannel == NULL)
    {
      TRACE(( 1, "cannot create http data channel\n" ));
      adl_atSendResponse ( ADL_AT_UNS, "cannot create http data channel\r\n" );
      wip_close( http_ClientTestCtx.CnxChannel);
      ret =-1;
    }
  }

  return(ret);
}

and the traces (once more) are
HTTP Client Service test application : Init
[HTTP] new request GET xxx.xxx.xxx/get_data.php HTTP/1.1 @ 00485fa0
[HTTP] connect to host: xxx.xxx.xxx
http_ClientTestDataHandler: Start

http_ClientTestDataHandler: WIP_CEV_WRITE
?message=35998300065115220090327141325fs00555ff000000000000000

411 Length Required

Length Required

A request of the requested method GET requires a valid Content-length.

chunked Transfer-Encoding forbidden: /get_data.php

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. http_ClientTestDataHandler: Done http_ClientTestDataHandler: Status=411 http_ClientTestDataHandler: Reason="Length Required" [WIP] closing HTTP_DATA 0x485fa0 [HTTP] channel closed by server [WIP] closing TCPCLIENT 0x486220

Also why does it say “[HTTP] new request GET xxx.xxx.xxx/get_data.php HTTP/1.1”. I make a POST request and it is in WIPHTTP/1.0
It drives me nuts…

That sounds like just another symptom of this:

If chunked transfers are not supported then a Length would be required…

Is it possible that there’s something in the mobile network that is substituting GET for POST…?

Have you tried a different operator?

But as you can see in my code i send the length of the data that i want to send in the header…