Dear TI Members,
I am working on the sdk example,"httpserver_MSP_EXP432E401Y_tirtos_ccs". In my application i would like to GET AND POST some parameters like baud rate, data bits from html web page.
I have developed a sample web page "index.html" and for that i have generated "index.h" file by using "makefsfile.exe".
And i am calling the "index.html" web page in "URLSimple_process" using URLHandler_GET method and
HTTPServer_sendSimpleResponse(ssock, returnCode, contentType,INDEX_SIZE,index) function.
So after downloading the code, i have opened corresponding html page using: ip_address/index.html. and it was successfully opening the web page.
Now, i would like to know how to retrieve the data using URLHandler_POST method and also what are the changes i need to do in html page and in URLSimple_process function.
My html code:
<html> <head> <title> PORT SETTINGS </title> <head> <body> <div id="heading"> <table width="100%"> </div> Serial Parameters<br /> BaudRate: <select name = "BaudRate"> <option>4800 <option selected>9600 </select> <br> Data bits: <select name = "Data bits"> <option>7 <option selected>8 </select> <br> <br/> </div> <input type="submit" value="Submit" name="submit" /> </table> </div> </body> </html> URLSimple_process Function: int URLSimple_process(URLHandler_Handle urlHandler, int method, const char * url, const char * urlArgs, int contentLength, int ssock) { int status = URLHandler_ENOTHANDLED; char *body = NULL; /* Body of HTTP response in process */ char *contentType = "text/html"; /* default is "text/plain", but can be overridden */ char *retString = NULL; /* String retrieved from server */ char *inputKey = NULL; /* Name of value to store in server */ char *inputValue = NULL; /* Value to store in server */ char argsToParse[MAX_DB_ENTRY_LEN]; int returnCode; /* HTTP response status code */ int retc; /* Error checking for internal funcs */ /* Determine the corresponding URL on the server */ if (strcmp(url, "/index.html") == 0) { if (method == URLHandler_GET) { body = "/get 'login.html': This is the login page."; returnCode = HTTP_SC_OK; status = URLHandler_EHANDLED; HTTPServer_sendSimpleResponse(ssock, returnCode, contentType, INDEX_SIZE, INDEX); } else if (method == URLHandler_POST) { inputValue = strtok(NULL, "="); retc = serverPost(inputKey, inputValue); if (retc == ERR_BAD_INPUT) { body = "Failed to POST. The data string is invalid."; returnCode = HTTP_SC_BAD_REQUEST; status = URLHandler_EERRORHANDLED; } else if (retc == ERR_DB_FULL) { body = "Database is full"; returnCode = HTTP_SC_SERVICE_UNAVAILABLE; status = URLHandler_EERRORHANDLED; } else { body = "Data string successfully posted to server."; returnCode = HTTP_SC_OK; status = URLHandler_EHANDLED; } } } else if(method == URLHandler_PATCH) { body = "PATCH is not handled by any handlers on this server."; returnCode = HTTP_SC_METHOD_NOT_ALLOWED; status = URLHandler_ENOTHANDLED; } else if(method == URLHandler_DELETE) { body = "DELETE is not handled by any handlers on this server."; returnCode = HTTP_SC_METHOD_NOT_ALLOWED; status = URLHandler_EERRORHANDLED; } if (status != URLHandler_ENOTHANDLED) { if (contentLength > 0) { char *buf; buf = malloc(contentLength); /* This is done to flush the socket */ (void) Ssock_recvall(ssock, buf, contentLength, 0); free(buf); } HTTPServer_sendSimpleResponse(ssock, returnCode, contentType, body ? strlen(body) : 0, body ? body : NULL); } return (status); }
[TI - code copied to file:example_html_code.txt]
I am new to this html programming and networking...
Help me on this.. I struck here from a long time...
Thanks & Regards
Kalyan.