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?