Communicating over network through http

Hi,

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:
//---------------------------
POST / HTTP/1.1
Content-Type: text/plain; charset=utf-8
Host: 192.168.1.94:6565
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 (https://processing.org/reference/libraries/net/Server_available_.html) works out of the box - does OF have something similar?

Thanks

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
	}
	else{
		//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 = "http://192.168.1.68:9000/";
form.method = OFX_HTTP_POST;
form.addFormField("number", ofToString(counter));
httpUtils.addForm(form);

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:

POST / HTTP/1.1
Content-Type: text/plain; charset=utf-8
Host: 192.168.1.94:6565
Content-Length: 4
Expect: 100-continue
Connection: Keep-Alive
TESTMSG

EDIT

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 = "http://192.168.1.68:9000";
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.

EDIT 2:

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”);