Can anyone lend some assistance as the brain is going to mush over this issue, and the lack of error log is making it difficult to resolve
so from the following above..
***********
ON MAIN
***********
- include "PostHandler.h"
get your IP ready code goes here
HTTPServer svr; initialize server object
svr.bind(80); let server to listen to standard HTTP port
svr.addHandler<PostHandler>("/android"); add a handler named PostHandler (executed when received "http://your_ip/android")
while(1)
{
Net::poll(); start listening
}
yes got that - listen for stuff thats posted to '/android'.
see comments
yes understand #includes no probs there
- ifndef POST_HANDLER_H
- define POST_HANDLER_H
- include "../HTTPRequestHandler.h"
- include "../HTTPRequestDispatcher.h"
handles POST request
class PostHandler : public HTTPRequestHandler
{
public:
PostHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
virtual PostHandler();
static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket){return new PostHandler(rootPath, path, pTCPSocket);}
virtual void doGet();
virtual void doPost();
virtual void doHead();
virtual void onReadable();
virtual void onWriteable();
virtual void onClose();
0 what aree these things doing?
};
- endif
does the cpp file live in the same folder as the compiled or where shoud it reside.
***********
ON PostHandler.cpp
***********
- include "PostHandler.h"
- include "string.h"
PostHandler::PostHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket):HTTPRequestHandler(rootPath, path, pTCPSocket){
}
PostHandler::PostHandler(){
}
void PostHandler::doGet(){
}
getting the post data and headers how do we echo the data to the terminal window for error checking?
void PostHandler::doPost()
{
get post variables
string _path = path();
string _rootpath = rootPath();
int _datalen = dataLen();
grab header variables
string _content_length = reqHeaders()["Content-Length"];
string _content_type = reqHeaders()["Content-Type"];
string _user_agent = reqHeaders()["User-Agent"];
string _expect = reqHeaders()["Expect"];
}
void PostHandler::doHead(){
}
empty function.
void PostHandler::onReadable(){
Serial pcx(USBTX, USBRX);
int _datalen = dataLen(); read POST data length
allocate size of readable data
char* _read_data = (char *) malloc(sizeof(char) * _datalen);
read POST data
readData(_read_data, _datalen);
pcx.printf("\r\n\r\nPOST Data\t:\t%s\r\n", _read_data);
create a response
char *http_response = "This is my reply";
setContentLen(strlen(http_response));
respHeaders()["Content-Type"] = "text/plain; charset=utf-8";
respHeaders()["Connection"] = "close";
writeData(http_response, strlen(http_response));
}
void PostHandler::onWriteable(){
close();
}
void PostHandler::onClose(){
return;
}
any help would be gratefully appreciated
Mark
Hi all am currently experimenting with embed and i am very impressed with it I have a question. I can get the mbed to act as webserver but i would like to control the leds via webpage control where can i get the post data that is sent when the submit button is pressed any help appreciated as i cant see where to get the page data or do you have to go via a handler. i did look at rpc but my braincell gave up many thanks for your time Chris