Problem with WIP_CEV_READ using HTTP Post


#1

Hi all,

I have tried to use HTTP post to call the web service that is created by ASP.NET and running in IIS 5.1, Through the tcp protocol analysis tool of Wireshark, it can be found that the web service can receive the request of the http post, and sent the right result to the modem (Fastrace Supreme 10), However in modem side, the req_event of WIP_CEV_READ also can be triggered, but there is not any data that can be read by wip_read(), see the code as below, and the code is based on the example code of HTTP GET, the WIP library version is 5.00.2050,

/****************************************************************************
 * File    :   entry_point.c                                            
 *
 * HTTP application:
 * - Configure url [HTTP_STR_URL]
 */

/*
    $LogWavecom$
 * --------------------------------------------------------------------------
 *  Date     | Author | Revision       | Description
 * ----------+--------+----------------+-------------------------------------
 *  25.01.07 | RFN    | 1.0            | Initial revision
 * ----------+--------+----------------+-------------------------------------
 *  12.03.08 | MBU    | X.X            | Correction of tracker ANO46671 
 * ----------+--------+----------------+------------------------------------- 
*/

#include "adl_global.h"  // Global includes 
#include "wip_http.h"    // WIP http services

/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/
// HTTP defined strings set
// ------------------------
const ascii * HTTP_STR_URL = "http://server_xxx/webservice/Service1.asmx/MyAdd";
const ascii * HTTP_POST_CONTENT  = "i=1&j=7";

typedef struct
{
  wip_channel_t CnxChannel;           // session channel
  wip_channel_t DataChannel;          // data channel

  u32           dataLength;           // response data length

} http_ClientTestCtx_t;

http_ClientTestCtx_t http_ClientTestCtx;


/*************/
/* Constants */
/*************/


/***************************************************************************/
/*  Local functions                                                        */
/***************************************************************************/


/***************************************************************************/
/*  Function   : http_ClientTestDataHandler                                */
/*-------------------------------------------------------------------------*/
/*  Object     : Handler for the HTTP data channel                         */
/*                                                                         */
/*  Returned   : none                                                      */
/*                                                                         */
/*                                                                         */
/*--------------------+---+---+---+----------------------------------------*/
/* Variable Name      |IN |OUT|GLB| Use                                    */
/*--------------------+---+---+---+----------------------------------------*/
/*                    |   |   |   |                                        */
/***************************************************************************/
static void http_ClientTestDataHandler( wip_event_t *ev, void *ctx)
{
  ascii tmpbuf[512];
  ascii Ptr_OnTrace[512];
  int len, tmplen;
  s32 status;
  http_ClientTestCtx_t *pHttpClientCtx =
    (http_ClientTestCtx_t *) &http_ClientTestCtx;

  s16 retWrite = 0;
  ascii msgbuf[50] = "i=1&j=7";

  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" ));      
    
      adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: WIP_CEV_READ\r\n" );
    
      // we must read all available data to trigger WIP_CEV_READ again
      tmplen = 0;
      while ( (len = wip_read( http_ClientTestCtx.DataChannel/*ev->channel*/, tmpbuf, sizeof(tmpbuf)-1)) > 0 )
      {
        tmpbuf[len] = 0;
        adl_atSendResponse ( ADL_AT_UNS, tmpbuf );
        tmplen += len;
        adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: wip_read: 1\r\n" );        
      }
      
      TRACE(( 4, "http_ClientTestDataHandler: read %d bytes\n", tmplen ));
      
      wm_sprintf(Ptr_OnTrace, "\r\n http_ClientTestDataHandler: read totally %d bytes\n", tmplen);
      adl_atSendResponse ( ADL_AT_UNS, Ptr_OnTrace );
      //
      
      // compute total length of response
      pHttpClientCtx->dataLength += tmplen;
      break;
 
    case WIP_CEV_WRITE:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_WRITE\n" ));
      
      adl_atSendResponse ( ADL_AT_UNS, "\r\nhttp_ClientTestDataHandler: WIP_CEV_WRITE\r\n" );

      retWrite = wip_write(http_ClientTestCtx.DataChannel/*ev->channel*/, msgbuf, wm_strlen(msgbuf));
      // Need to signal the end of the message body
      wip_shutdown(http_ClientTestCtx.DataChannel/*ev->channel*/, FALSE, TRUE);
      
      break;

    case WIP_CEV_PEER_CLOSE:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_PEER_CLOSE\n" ));
       
      // end of data
      // show response information
      if( wip_getOpts( http_ClientTestCtx.DataChannel/*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));
        wm_sprintf(Ptr_OnTrace, "http_ClientTestDataHandler: Reason=\"%s\"\n", tmpbuf);
        TRACE((4,Ptr_OnTrace));
      }
      if( wip_getOpts( http_ClientTestCtx.DataChannel/*ev->channel*/,
            WIP_COPT_HTTP_HEADER, "content-type", tmpbuf, sizeof(tmpbuf),
            WIP_COPT_END) == OK) 
      {
            wm_sprintf(Ptr_OnTrace, "http_ClientTestDataHandler: Content Type=\"%s\"\n", tmpbuf);
            TRACE((4,Ptr_OnTrace));
      }          
      TRACE(( 4, "http_ClientTestDataHandler: Response Length=%d bytes\n",
              pHttpClientCtx->dataLength ));
    
      // if OK, and finished
      if (status == 200)
      {
        // data channel must be closed
        wip_close( http_ClientTestCtx.DataChannel/*ev->channel*/);
      }

      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( http_ClientTestCtx.DataChannel/*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;

  // 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_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, "Content-Type", "application/x-www-form-urlencoded",
                                                 
                    // request headers
                    WIP_COPT_HTTP_HEADER, "Accept", "text/xml",                                             
                                                            
                    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);
}


/***************************************************************************/
/*  Function   : appli_entry_point                                         */
/*-------------------------------------------------------------------------*/
/*  Object     : Called once the WIP IP stack is fully initialized.        */
/*               This is the starting point of user applications.          */
/*-------------------------------------------------------------------------*/
/*  Variable Name     |IN |OUT|GLB|  Utilisation                           */
/*--------------------+---+---+---+----------------------------------------*/
/*                    |   |   |   |                                        */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void appli_entry_point(void)
{
  TRACE (( 1, "HTTP Client Service test application : Init" ));
  adl_atSendResponse ( ADL_AT_UNS, "\r\nHTTP Client Service test application : Init\r\n" );

  http_ClientTestCreate();
}

So why the wip_read() can not read any data after the web service has been sent the right result to modem?

Is there anyone can help me? thank you very much.