HTTP with method POST problem in Q2686


#1

Hi,
I want to use HTTP with method POST. The default method GET is correct the server return data but with the method POST it’s impossible no server request and of course no reponse !
what’s wrong ? Have you any idea ?

My device is a Q2686 with a 6.62firmware and wip_IP_lib 3.00.06

//----------------------------------------------------------------------
wip_channel_t http;
static char urlBuff[256];
//----------------------------------------------------------------------
u8 http_OpenSession( const char *pURL )	// Try to open session
{
      // setup HTTP session
      http = wip_HTTPClientCreateOpts(NULL, NULL, 
           WIP_COPT_HTTP_HEADER, "User-Agent",
           "WIP-HTTP-Client/1.0", WIP_COPT_END);

      // Get Html page 
      wip_getFileOpts( http, "http://<server>...", http_event, NULL,
         WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,
         WIP_COPT_HTTP_HEADER, "Accept", "text/html",
         WIP_COPT_HTTP_HEADER, "Content-Type", "application/x-www-form-urlencoded",
         WIP_COPT_END);

	return 0;
}

//----------------------------------------------------------------------
void http_event( wip_event_t *ev, void *ctx )
{
	wip_channel_t ch;
	u8 buf[128];
	s32 ret;
	int wrt;

	// Get originating channel
	ch = ev->channel;
	switch(ev->kind)
	{
		case WIP_CEV_OPEN:
			// Get status code
			TRACE((1,"##HTTP Open"));
			break;

		case WIP_CEV_READ:
			TRACE((1,"##HTTP READ!"));
			// Read Data from server
			while((ret = wip_read(ch, buf, sizeof(buf)-1))>0)
			{
				buf[ret]='\0';
				dial_reponse(buf);
			}
			break;

		case WIP_CEV_WRITE:
			wrt = wm_sprintf(buf,"IMEI=1&Ref=0\r\n\r\n");
			// Write POST argument to HTTP request
			wrt = wip_write(ch, buf, wrt);
			TRACE((1,"##HTTP WRITE for Post[%x]",wrt));
			wip_shutdown(ch,FALSE,TRUE);

		case WIP_CEV_PEER_CLOSE:
			wip_close(ch);
			break;

		case WIP_CEV_ERROR:
			wip_close(ch);
			break;
	}
}

:smiley: Thank you in advance for your help.


#2

hi,

in your code, you missed a “break” in case of WIP_CEV_WRITE event occured !

case WIP_CEV_WRITE: 
         ...
         break;

case WIP_CEV_PEER_CLOSE:
         ...

#3

:open_mouth: Waouh ! tomorrow i’ll buy new eyes, Thank’s “afaurep”.
Just another question : I want to use POST methode with mutlipart/form-data, I think “content-length” and “boundary” is not include automaticaly by wip_lib ?
Thank’s for your help


#4

i think wip_lib doens’t add automatically multipart/form-data and boundary field. you must do it. i also try to send file through HTTP POst method. So, let me know if it works !


#5

Hi,
After most try ; first “multipart/form-data” must be write in code, second “content-length” is not need because and header is automaticaly add by wip_lib “Transfer-Encoding: chunked”. More infos later…


#6

I didn’t see this mentioned in the User Guide - is it documented?

Did I just miss it?


#7

I still haven’t seen it documented, but I’ve given it a try:

The ‘content-length’ header field is not automatically added by WIP (not by v2, at least);

However, omitting the ‘content-length’ header field doesn’t (necessarily) seem to be a problem, as the receiver can still identify the proper length of the body from the “chunked” encoding. :slight_smile:


#8

In fact, the HTTP spec specifically states that a ‘content-length’ header field must not be sent when a ‘Transfer-Encoding’ header is present.

In fact, again, the HTTP spec specifically states that the receiver must ignore a ‘content-length’ header if the message also contains a ‘Transfer-Encoding’ header.

See: w3.org/Protocols/rfc2616/rfc … tml#sec4.4