Re: Help needed with uploading data to HTTP Server

"markreds81" <[email protected]>
Newsgroups gmane.comp.hardware.rabbit-semiconductor
Message-ID <[email protected]>
It depends how did you set your initialization. To enable cgi funtions (in the new style, as your example) your have to:

1) #define USE_HTTP_UPLOAD
2) register the MIME type in your static table
3) register the function in the HTTP web server (with authentication, if you want)

This is a example:

#define USE_HTTP_UPLOAD

int http_myCGI(HttpState *state);

SSPEC_MIMETABLE_START
   SSPEC_MIME(".cgi", "")
SSPEC_MIMETABLE_END

SSPEC_RESOURCETABLE_START
   SSPEC_RESOURCE_P_FUNCTION("/my.cgi", http_cabinetsCGI, "my1", ADMIN_GROUP, ADMIN_GROUP, SERVER_HTTP, SERVER_AUTH_BASIC)
SSPEC_RESOURCETABLE_END

_debug int http_myCGI(HttpState *state) {
   int rc;

   rc = 0;
   switch (http_getAction(state)) {
      case CGI_START:
         // see manual reference for see what you can do here
         break;
      case CGI_DATA:
         // here you get a chunk of data, you can process or save in local buffer or FAT file
      case CGI_END:
         // end of POST data, see manual reference
         break;
      ..
      ..
      case CGI_EOF:
         // when you finish, remember to send to client at least a
         // header HTTP response (HTTP 1.0 200 OK). You can do this
         // with this function, see HTTP.LIB
         http_genHeader(state, http_getData(state), HTTP_MAXBUFFER, 200, NULL, 0, NULL);
         // then tell to HTTP server that you have finished to process the request and do not call this function anymore.
         rc = CGI_SEND_DONE;
         break;
   }
   
   return rc;
}

If you want you can also send to client an entire page or existing FAT file by switching/redirecting to. You can also produce the entire response in another cgi.

In your example you should return 0 only if you haven't finished to process the request so the HTTP server will call your function again with another chunk of data, or another state. But at the end return something else (1, CGI_DONE, CGI_SEND_DONE...). Or else you client will wait until a socket time-out will occurs.

I hope this can help you.

--- In [email protected], "racqueldesign" <embeddedsupplies@...> wrote:
>
> Hi,
> 
> I need help with uploading(maybe posting is the proper word) data to my HTTP server.  I have read the document on uploading files but this is a simple data upload and the skeleton example isn't working me.  Can someone please tell me what I am doing wrong.
> 
> The HTTP Server doesn't have a webpage to accept FORM. It simple respond to upload data.  Example of the data in the body of the HTTP request i am require to upload is :
> {
>     "sensor 2": 1,
>     "name": "contact sensor",
>     "username": "sandy",
>     "password": "access",
>     "msg": [{"update"}]
> } 
> --------------------skeleton example in the document-------------
> int my_CGI(HttpState * s)
> {
>   switch(http_getAction(s)) {
>     case CGI_START:
>     break;
>     case CGI_DATA:
>     break;
>     case CGI_END:
>     break;
>     case CGI_EOF:
>     break;
>     case CGI_ABORT:
>     break;
>   }
>   return 0;
> }
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.