Wip_http_method_get

I tried to send data to our server with HTTP POST but it did not work. I posted my code on this forum and i did not receive any feedback probably because my code was ok. The server kept on sending the following response to me:

[HTTP] new request GET weather.vodafonernd.com/post.php HTTP/1.1 @ 180ec800
[HTTP] req parsed URL: /post.php at weather.vodafonernd.com
[HTTP] connect to host: weather.vodafonernd.com:80
HTTP data channel created
http_ClientTestDataHandler: Start
http_ClientTestDataHandler: WIP_CEV_WRITE
date_time=2009-05-06+10’ A’14’ A’54&temp=20.0
http_ClientTestDataHandler: 160 bytes written
http_ClientTestDataHandler: WIP_CEV_READ
http_ClientTestDataHandler: Status=400
http_ClientTestDataHandler: Reason=“Bad Request ( The HTTP request includes a non-supported header. Contact your ISA Server administrator. )”
[WIP] closing HTTP_DATA 0x180ec800
[HTTP] destroy request @ 180ec800
[WIP] closing HTTP_CONTROL 0x180ec5c0
[WIP] closing TCPCLIENT 0x180ec060

I commented all my headers and used only one header
WIP_COPT_HTTP_HEADER, “Host”, “weather.vodafonernd.com”,
but i still received the same status=400.

We concluded that HTTP POST will not work. We tried HTTP GEt and i could read data from the website. Then i tried to send data to the server after reading from the channel, but it writes only zeroes. That means after calling the wip_read function, i call the wip_write function.

[b][HTTP] new request GET weather.vodafonernd.com/post.php HTTP/1.1 @ 180dd44c
TEST PARSE_URLPARSE_URL HTTPS ? 0PARSE_URL STEP3[HTTP] req parsed URL: /post.php at weather.vodafonernd.com
[HTTP] connect to host: weather.vodafonernd.com:80
[WIP] new TCPCLIENT 0x180dc14c
HTTP data channel created
[req_event] WIP_CEV_OPEN
[req_event] WIP_CEV_WRITE
http_ClientTestDataHandler: Start
[req_event] WIP_CEV_READ
http_ClientTestDataHandler: WIP_CEV_READ

http_ClientTestDataHandler: 34 bytes read
date_time=2009-05-12+10:29:25&temp=21.1
http_ClientTestDataHandler: -1998bytes written
[WIP] closing HTTP_DATA 0x180dd44c
[HTTP] destroy request @ 180dd44c
[WIP] closing HTTP_CONTROL 0x180dd20c
[WIP] closing TCPCLIENT 0x180dc14c[/b]

As you can see it does not write any data because the wip_write function returns a negative number in this case -1998.
The data i’m sending to the server is date_time=2009-05-12+10:29:25&temp=21.1
But on the server i only see zeroes.

Hiya,

You can ONLY send data using the HTTP GET request if you encode the data to be sent into the command line. You CAN’T do a GET request and then try to sent data…

Likewise with a POST request. You make the connection, write the data, then read the response from the server.

At first glance, your POST response has a couple of potential problems:

  1. The first line of the response indicates that you have used a GET response - although there have been some queries rased about this behaviour elsewhere on the forum.
  2. Your data (date_time…) does not look as though it’s been correctly URL encoded

Check out (at least) the following threads:

I also strongly recommend that you check out HTTP Made Really Easy for a good primer on writing a HTTP client (which is what you are doing).

ciao, Dave

Davidc,
It is a POST request i can assure you, the default method in the wip_getFileOpts is HTTP_GET thatz why it says GET,. I hope Wavecom will correect that typographical error. You are right my date_time is not urlencoded it is because i posted the first traces i received 1 week ago. I later used urlencoding and i had the same error. The problem is with the header. We used wireshark sniffer to sniff the HTTP_POST request, here is what we got:

Hypertext Transfer Protocol
POST /post.php HTTP/1.1\r\n
Request Method: POST
Request URI: /post.php
Request Version: HTTP/1.1
Host: weather.vodafonernd.com\r\n
Transfer-Encoding: chunked\r\n
Host: weather.vodafonernd.com\r\n
\r\n
HTTP chunked response
End of chunked encoding
Chunk size: 0 octets
Chunk boundary

Probabver does not support chunked transfer. How can i solve this problem ?

WIPSOFT adds the following commands when you issue an HTTP request.
Transfer-Encoding: chunked\r\n
Host: weather.vodafonernd.com\r\n

So there is no way i can remove it. I looked at

en.wikipedia.org/wiki/List_of_HTTP_headers

Transfer-Encoding is not an HTTP request, it is an HTTP response. The correct request is TE

Hiya,

There’s been another post here on the forum about issues with HTTP POST, Chunked-encoding and Vodafone. A far as I am aware, the issue was not resolved. I’m not using Vodafone, and have no experience of this issue.

My reading of the RFC is that the TE header is used in conjunction with Chunked-Encoding to indicate that there are trailing headers after the chunked data. I also believe that the server should ignore any headers that it doesn’t understan or can’t process - so sending a Transfer-Encoding: chunked header in the POST headers should not break a well-written server.

Can you actually capture the raw data with Wireshark? It looks like you have posted the decoded message. I would expect a POST request (coming from the client) to look something like this:

POST /post.php HTTP/1.1
Host: weather.vodafonend.com
Content-Type: application/x-www-form-urlencoded
Transfer-Encoding: chunked

13
data=fred&name=nurk

ciao, Dave

I’ve solved the problem. I followed the advice of the following post:
viewtopic.php?f=16&t=2148&p=7929&hilit=chunked+transfer+encoding#p7929

Our server is a virtual one and i think it does not support chunked transfer. I changed the HTTP version to 1.0 and specified the content length and it works. But i still have one problem, i create a session and data channel every 30secs because i want to send the data every 30secs. It sends the data the first time and i get status code 200 but the next time it gives me status code 500:The specified network name is no longer available

M2M Weather Station: Application Started
SIM not subscribed
2
SIM not subscribed
5
SIM subscribed
3
Not Registered on GPRS network
Registered on GPRS network
[GPRS]: open: -> DISCONNECTED
[GPRS]: start: -> CONNECTING
[GPRS]: GPRS EVENT SETUP OK (cid=1): GPRS activate
[GPRS]: GPRS EVENT: 27 (cid=1)
[GPRS]: GPRS EVENT ACTIVATE OK (cid=5)
[GPRS]: GPRS: -> CONNECTED
WIP_BEV_IP_CONNECTED
http session channel created
[HTTP] new request PUT weather.vodafonernd.com/post.php HTTP/1.0 @ 180dd478
TEST PARSE_URLPARSE_URL HTTPS ? 0PARSE_URL STEP3[HTTP] req parsed URL: /post.php at weather.vodafonernd.com
[HTTP] connect to host: weather.vodafonernd.com:80
[WIP] new TCPCLIENT 0x180dc778
HTTP data channel created
[req_event] WIP_CEV_OPEN
[req_event] WIP_CEV_WRITE
http_ClientTestDataHandler: Start
http_ClientTestDataHandler: WIP_CEV_WRITE
date_time=2009-05-12%2015%3A16%3A01&temp=21.5
http_ClientTestDataHandler: 45 bytes written
[req_event] WIP_CEV_READ
http_ClientTestDataHandler: WIP_CEV_READ
http_ClientTestDataHandler: 34 bytes read
http_ClientTestDataHandler: Done
http_ClientTestDataHandler: Status=200
http_ClientTestDataHandler: Reason=“OK”
[WIP] closing HTTP_DATA 0x180dd478
[HTTP] destroy request @ 180dd478
[req_event] WIP_CEV_PEER_CLOSE

http session channel created
[HTTP] new request PUT weather.vodafonernd.com/post.php HTTP/1.0 @ 180dd478
TEST PARSE_URLPARSE_URL HTTPS ? 0PARSE_URL STEP3[HTTP] req parsed URL: /post.php at weather.vodafonernd.com
[HTTP] connect to host: weather.vodafonernd.com:80
[WIP] new TCPCLIENT 0x180dd638
HTTP data channel created
[req_event] WIP_CEV_OPEN
[req_event] WIP_CEV_WRITE
http_ClientTestDataHandler: Start
http_ClientTestDataHandler: WIP_CEV_WRITE
date_time=2009-05-12%2015%3A16%3A31&temp=21.5
http_ClientTestDataHandler: 45 bytes written
[req_event] WIP_CEV_READ
http_ClientTestDataHandler: WIP_CEV_READ
http_ClientTestDataHandler: 348 bytes read
[req_event] WIP_CEV_READ
http_ClientTestDataHandler: WIP_CEV_READ
http_ClientTestDataHandler: 536 bytes read
[req_event] WIP_CEV_READ
http_ClientTestDataHandler: WIP_CEV_READ
http_ClientTestDataHandler: 536 bytes read
[req_event] WIP_CEV_READ
http_ClientTestDataHandler: WIP_CEV_READ
http_ClientTestDataHandler: 536 bytes read
[req_event] WIP_CEV_READ
http_ClientTestDataHandler: WIP_CEV_READ
http_ClientTestDataHandler: 158 bytes read
http_ClientTestDataHandler: Done
http_ClientTestDataHandler: Status=500
http_ClientTestDataHandler: Reason="( The specified network name is no longer available. )"
[WIP] closing HTTP_DATA 0x180dd478
[HTTP] destroy request @ 180dd478
[req_event] WIP_CEV_PEER_CLOSE

How can i solve this problem ?

I think it will be helpful if you look at my code:

const ascii * HTTP_STR_URL = “http://weather.vodafonernd.com/post.php”;

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;
wip_cstate_t wip_state;
ascii writbuf[45];
void fillwritbuf(void)
{
s16 m,n,p,w;

  m = (s16) GPIO26info_t.TenMinTemp * 10; // Decimal precision: 1 digit
  n = (GPIO26info_t.TenMinTemp * 10 ) - m; // Decimal precision: 1 digit

  p = (s16) GPIO26info_t.TenMinHum * 10; // Decimal precision: 1 digit
  w = (GPIO26info_t.TenMinHum * 10 ) - p; // Decimal precision: 1 digit

wm_sprintf(writbuf, “date_time=%04lu-%02lu-%02lu%s%02lu%s%02lu%s%02lu&temp=%d.%01d”,
GPStimedate_t.year,
GPStimedate_t.month,
GPStimedate_t.day,
“%20”,
GPStimedate_t.hour,
“%3A”,
GPStimedate_t.minute,
“%3A”,
GPStimedate_t.seconds,
(s16)GPIO26info_t.TenMinTemp, n);
}

/********************************************************************/
/
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[80];

ascii readbuf[256];
s32 BytesWritten, len, tmplen;
s32 status;
ascii info[50];
http_ClientTestCtx_t *pHttpClientCtx =
(http_ClientTestCtx_t ) &http_ClientTestCtx;
/
How many bytes of [tmpbuf] have already been sent. */
static int offset = 0;

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” );
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, “\r\nhttp_ClientTestDataHandler: Start\r\n”);
// ready for writing data
pHttpClientCtx->dataLength = 0;
break;

case WIP_CEV_READ:
 adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\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(ev->channel, readbuf, sizeof(readbuf)-1)) > 0) {
    	   readbuf[len] = 0;
        // adl_atSendResponse ( ADL_AT_UNS, readbuf );
         tmplen += len;
    }
 TRACE(( 4, "http_ClientTestDataHandler: read %d bytes\n", tmplen ));
 wm_sprintf( tmpbuf, "\r\nhttp_ClientTestDataHandler: %d bytes read\r\n", tmplen);
 adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, tmpbuf);
// compute total length of response
 pHttpClientCtx->dataLength += len;

 break;

case WIP_CEV_WRITE:
      TRACE(( 4, "http_ClientTestDataHandler: WIP_CEV_WRITE\n" ));
      adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp_ClientTestDataHandler: WIP_CEV_WRITE\r\n");
      wip_state = wip_getState(ev->channel);

      if (wip_state==WIP_CSTATE_READY || WIP_CSTATE_BUSY) //&& GPSposition_t.fix_ok == TRUE)
      {
          // we must write all available data to trigger WIP_CEV_WRITE again
           BytesWritten = wip_write(  ev->channel, writbuf, sizeof(writbuf)-offset);
           if(BytesWritten < 0)
           {/* error */
               wip_debug( "HTTP write error %i\n", BytesWritten);
               adl_atSendResponse ( ADL_AT_UNS, "\r\nwip_write error\r\n" );
	           return;
            }
            offset += BytesWritten; /* Update the number of bytes sent. */
            pHttpClientCtx->dataLength += offset;
            if( offset == sizeof( writbuf)) { /* All of [buffer] has been sent */
            TRACE(( 4, "http_ClientTestDataHandler: bytes %d written\n", offset ));
            adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1,writbuf);
            wm_sprintf( info, "\r\nhttp_ClientTestDataHandler: %d bytes written\r\n", offset);
            adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, info);
            }
            wip_shutdown(ev->channel,FALSE,TRUE);
       }
     /* else if  (GPSposition_t.fix_ok == FALSE){
    	  wip_shutdown( http_ClientTestCtx.DataChannel,FALSE,TRUE);
    	  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nCannot send HTTP data: No GPS fix\r\n");
      }*/
      else if  (wip_state==WIP_CSTATE_TO_CLOSE)
      {
    	  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nData channel is broken\r\n");
    	  wip_close( ev->channel);
      }

  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( http_ClientTestCtx.DataChannel,
	            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( http_ClientTestCtx.DataChannel,
	            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_ERROR:
  TRACE(( 2, "http_ClientTestDataHandler: WIP_CEV_ERROR %d\n",
          ev->content.error.errnum));
  //adl_atSendResponse ( ADL_AT_UNS, "http_ClientTestDataHandler: ERROR\r\n" );
  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp_ClientTestDataHandler: ERROR\r\n");
  // connection to server broken
  wip_close( ev->channel);

  break;

default:
  TRACE(( 2, "http_ClientTestDataHandler: unexpected event: %d\n",
          ev->kind));
  adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nunexpected event\r\n");
  break;

}
}

static s32 http_Client(void)
{
s32 ret = 0;

//fill buffer with data
fillwritbuf();

// HTTP Session creation
// ---------------------------
http_ClientTestCtx.CnxChannel = wip_HTTPClientCreateOpts(
                                    NULL,  // no handler
                                    NULL,  // no context
                                    WIP_COPT_HTTP_VERSION, WIP_HTTP_VERSION_1_0,
                                    WIP_COPT_END);

if (http_ClientTestCtx.CnxChannel == NULL)
  {
    TRACE(( 2, "cannot create http session channel\n" ));
    //adl_atSendResponse ( ADL_AT_UNS, "cannot create http session channel\r\n" );
    adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\ncannot create http session channel\r\n");
    ret = -1;
  }
 else {
	adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nhttp session channel created\r\n");

   // HTTP POST command
    http_ClientTestCtx.DataChannel = wip_putFileOpts(
    		                             http_ClientTestCtx.CnxChannel,  // session channel
    		                             HTTP_STR_URL,                   // URL to receive the data
      		                             http_ClientTestDataHandler,     // data handler
      		                             &http_ClientTestCtx,            // context
      		                             WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,

      		                             // request headers
      		                             WIP_COPT_HTTP_HEADER, "Content-Length", "45",
      		                             WIP_COPT_HTTP_HEADER, "Accept", "text/plain",
      		                             WIP_COPT_HTTP_HEADER, "Connection", "keep-alive",
      		                             WIP_COPT_HTTP_HEADER, "Content-Type", "application/x-www-form-urlencoded",
      		                             WIP_COPT_HTTP_HEADER, "Host", "weather.vodafonernd.com",
      		                             WIP_COPT_END);

      		    if (http_ClientTestCtx.DataChannel == NULL)
      		    {
      		      TRACE(( 2, "cannot create http data channel\n" ));
      		      //adl_atSendResponse ( ADL_AT_UNS, "cannot create http data channel\r\n" );
      		      adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\ncannot create http data channel\r\n");
      		      wip_close( http_ClientTestCtx.CnxChannel);
      		     // ret =-1;
      		    }
      		    else
      		    	adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, "\r\nHTTP data channel created\r\n");
 }
  		    return(ret);

}

void GPRSTimerhdl(u8 TimerIdFive)
{
http_Client();
}

/*******************************************************************/
/
Function : evh_bearer /
/
-------------------------------------------------------------------------
/
/
Object : bearer events handler: when the bearer connection is /
/
completed, start IP services /
/
-------------------------------------------------------------------------
/
/
Variable Name |IN |OUT|GLB| Utilisation /
/
--------------------±–±--±–±---------------------------------------
/
/
b | X | | | bearer identifier /
/
event | X | | | bearer event type /
/
ctx | | | | unused /
/
--------------------±–±--±–±---------------------------------------
/
/***************************************************************************/
static void evh_bearer( wip_bearer_t b, s8 event, void *ctx) {
if( WIP_BEV_IP_CONNECTED == event) {
TRACE(( 4, “http_ClientTestDataHandler: WIP_BEV_IP_CONNECTED \n” ));
adl_atSendResponsePort ( ADL_AT_RSP, ADL_PORT_UART1, “\r\nWIP_BEV_IP_CONNECTED\r\n”);
adl_tmrSubscribe ( TRUE,300, ADL_TMR_TYPE_100MS, GPRSTimerhdl );
}
}

//
/
Function : open_and_start_bearer() /
/
--------------------------------------------------------------------------
/
/
Object : Open and start the GPRS bearer. Normally, the bearer will /
/
answer IN_PROGRESS, and the initialization will be finished /
/
by the callback evh_bearer(). /
/
--------------------------------------------------------------------------
/
/
Variable Name |IN |OUT|GLB| Utilisation /
/
--------------------±–±--±–±----------------------------------------
/
/
--------------------±–±--±–±----------------------------------------
/
/
********/
static void open_and_start_bearer( void) {
int r;
wip_bearer_t b;

r = wip_bearerOpen( &b, “GPRS”, evh_bearer, NULL);
ASSERT_OK( r);

r = wip_bearerSetOpts( b, WIP_BOPT_GPRS_APN, GPRS_APN,
WIP_BOPT_LOGIN, GPRS_USER,
WIP_BOPT_PASSWORD, GPRS_PASSWORD,
WIP_BOPT_END);
ASSERT_OK( r);
r = wip_bearerStart( b);
ASSERT( 0 == r || WIP_BERR_OK_INPROGRESS == r);
}