hi,
Iam using Q2687 wavecom CPU . i want to transmit data to HTTP through POST method . Iam sending the data to server (tomcat) by using the following code.The HTTP session takes place correctly by connection to host and the open and write request are happened and bytes are written through wip_write but it is not received in the server. Can anyone reply.
/*
- http_file.c
- Created on: Feb 18, 2010
-
Author: Administrator
*/
#include “adl_global.h” // Global includes
#include “wip_http.h” // WIP http services
/**************************************************************************/
/ Local variables /
/**************************************************************************/
// HTTP defined strings set
// ------------------------
char trsbuf[]=“12345”;
const ascii * HTTP_STR_URL = “http://url”;
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[256];
ascii Ptr_OnTrace[240];
int len, tmplen,BytesWritten;
s32 status;
http_ClientTestCtx_t *pHttpClientCtx =
(http_ClientTestCtx_t *) &http_ClientTestCtx;
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;
// BytesWritten = wip_write(ev->channel, trsbuf, sizeof(trsbuf));
//TRACE((1,"BytesWritten=%d",BytesWritten));
break;
case WIP_CEV_READ:
TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_READ\n" ));
adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler:read\r\n" );
// we must read all available data to trigger WIP_CEV_READ again
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 += tmplen;
break;
case WIP_CEV_WRITE:
adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler:write\r\n" );
TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_WRITE\n" ));
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp_ClientTestDataHandler: WIP_CEV_WRITE\r\n");
BytesWritten = wip_write(ev->channel, trsbuf, sizeof(trsbuf));
TRACE((1,"BytesWritten=%d",BytesWritten));
//wm_sprintf("%s",trsbuf);
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));
wm_sprintf(Ptr_OnTrace, "http_ClientTestDataHandler: Reason=\"%s\"\n", tmpbuf);
TRACE((4,Ptr_OnTrace));
}
if( wip_getOpts( 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 ));
// data channel must be closed
wip_close( 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( 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
WIP_COPT_HTTP_METHOD,WIP_HTTP_METHOD_POST,
// request headers
WIP_COPT_HTTP_HEADER, "Accept", "text/html",
WIP_COPT_HTTP_HEADER, "Accept-Language", "fr, en",
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();
}