Communicating over network through http


I need to communicate between 2 applications over a network. One of them is C# and basically sends an HTTP post (like below) over a specified port.

The message is something like:
Content-Type: text/plain; charset=utf-8
Content-Length: 4
Expect: 100-continue
Connection: Keep-Alive

test message

In OF I would like to receive that message but am having some trouble. I’ve tried the tcp server with no luck (I couldn’t seem to receive the string for some reason). I’ve also tried ofxHTTP but that seems too complicated for my needs. I’ve also tried ofxHttpServer and ofxWebServer but cannot get these to compile on Windows with VS.

In processing this example ( works out of the box - does OF have something similar?


This should be quite simple with ofxHTTP and the post example. Did you try the post server example? It just gives you an ofEvent with the contents of the POST (e.g. “test message”). I wasn’t clear what your errors were.

Thanks for the response Christopher. Using the post example ofxHTTP, I can get messages into OF. There were a couple of things that I could not figure out how to do though:

  1. Send back a specific message (for example - OK) when the post event is called. I’ve seen now that I can change the uploaded.html file to include my message but Ideally I’d like to send back different messages for different post requests so if I can do that in code it would be great. Something like:
void ofApp::onHTTPPostEvent(ofx::HTTP::PostEventArgs& args)
	string msg = args.getBuffer().getText();
	if (msg == "msg1"){
		//return OK
		//return NOT_OK
  1. Send a post request to a url at any time (on keypress or something). So something like how ofxHttpUtils works:
ofxHttpForm form;
form.action = "";
form.method = OFX_HTTP_POST;
form.addFormField("number", ofToString(counter));

Although I cannot use ofxHttpUtils because I do not want to add a form - I just want to add some content to the http message like this:

Content-Type: text/plain; charset=utf-8
Content-Length: 4
Expect: 100-continue
Connection: Keep-Alive


Have managed to get somewhere with posting HTTP using ofxHTTP using the client example - the only problem is that I cannot seem to add a body message.

std::string url = "";
ofx::HTTP::DefaultClient client;
ofx::HTTP::Context context;
ofx::HTTP::BaseResponse response;
ofx::HTTP::PostRequest request(url);
//request.addFormField("test", "val");
// Execute the request and get the response stream.
std::istream& responseStream = client.execute(request, response, context);
Poco::StreamCopier::copyStream(responseStream, std::cout);
std::cout << std::endl;

Btw: I noticed a bug in the library - the PostRequest class was actually adding a PUT request in the constructor.


I’ve managed to get it working. To send body content - I needed to do the following (note the form filed name is blank):
request.addFormField("", “TEST”);