# HTTP with method POST problem in Q2686

**URL:** <https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479>\
**Category:** Open AT\
**Created:** [July 30, 2007, 4:14pm UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479 "2007-07-30T16:14:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![octal](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@octal](https://forum.sierrawireless.com/u/octal)\
**Post date:** [July 30, 2007, 4:14pm UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479/1 "2007-07-30T16:14:24Z")

</div>

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

```auto
//----------------------------------------------------------------------
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;
	}
}
```

😃 Thank you in advance for your help.

---

<div class="post-metadata">

**Author:** ![afaurep](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@afaurep](https://forum.sierrawireless.com/u/afaurep)\
**Post date:** [July 31, 2007, 1:07pm UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479/2 "2007-07-31T13:07:32Z")

</div>

hi,

in your code, you missed a “break” in case of WIP\_CEV\_WRITE event occured !

```auto
case WIP_CEV_WRITE: 
         ...
         break;

case WIP_CEV_PEER_CLOSE:
         ...
```

---

<div class="post-metadata">

**Author:** ![octal](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@octal](https://forum.sierrawireless.com/u/octal)\
**Post date:** [July 31, 2007, 2:07pm UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479/3 "2007-07-31T14:07:12Z")

</div>

😮 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

---

<div class="post-metadata">

**Author:** ![afaurep](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@afaurep](https://forum.sierrawireless.com/u/afaurep)\
**Post date:** [July 31, 2007, 2:37pm UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479/4 "2007-07-31T14:37:58Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![octal](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@octal](https://forum.sierrawireless.com/u/octal)\
**Post date:** [August 1, 2007, 7:00am UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479/5 "2007-08-01T07:00:42Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 19, 2007, 4:09pm UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479/6 "2007-09-19T16:09:41Z")

</div>

> [@octal](#):
>
> “content-length” is not need because and header is automaticaly add by wip\_lib

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

Did I just miss it?

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 26, 2007, 3:20pm UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479/7 "2007-09-26T15:20:15Z")

</div>

> [@octal](#):
>
> “content-length” is not need because and header is automaticaly add by wip\_lib

> [@I](#):
>
> I didn’t see this mentioned in the User Guide - is it documented?

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. 🙂

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [September 26, 2007, 10:22pm UTC](https://forum.sierrawireless.com/t/http-with-method-post-problem-in-q2686/1479/8 "2007-09-26T22:22:24Z")

</div>

> [@I](#):
>
> The ‘content-length’ header field is not automatically added by WIP (not by v2, at least)

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

> [@I also](#):
>
> 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. 🙂

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](http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4)
