ofxHTTP post response

Hi

Im trying to do an jsonrpc using POST, im taking the simplePostServer as starting point. To the jsonrpc part im using https://github.com/uskr/jsonrpc-lean to parse the json data and handle request…

Im doing this

void ofApp::onHTTPPostEvent(ofx::HTTP::PostEventArgs& args)
{
    ofLogNotice("ofApp::onHTTPPostEvent") << "Data: " << args.getBuffer().getText();
    
    std::shared_ptr<jsonrpc::FormattedData> outputFormattedData;
    
    outputFormattedData.reset();
    
    std::cout << "request: " << args.getBuffer().getText() << std::endl;
    
    outputFormattedData = server.HandleRequest(args.getBuffer().getText());
    
    std::cout << "response: " << outputFormattedData->GetData() << std::endl;
}

but the server try to redirect to a html file “uploaded.html”

FileSystemRoute::handleRequest: File not found: ...... myApps/ProbaJsonRPC/bin/data/DocumentRoot/uploaded.html

Why it handle like if im uploading anything??¿¿ I only want to call postEvent not uploadEvent… I tried to find where the code redirects to “upload part” but i can not see where it will be.

I know that a ofxJsonRpc exist but i need to use with an http post server not with websockets.

Best!

solved, as usual, just a dumb question, i was not sending a reply.

std::string buffer = ofToString(outputFormattedData->GetData());


args.getResponse().setContentType("application/json");
args.getResponse().sendBuffer(buffer.c_str(),buffer.size());

just send the response and works ok.

By the way, ofxJSONRPC already uses ofxHTTP and handles JSONRPC function registration, etc. It also works with websockets or post requests. https://github.com/bakercp/ofxJSONRPC

Check it out!

I just posted a little more on this question here:

Ohhhhh, i undestand now!

I was not able to make an ofxJsonRpc server to talk with an Android native app client, wich dont uses websockets, and have to do this extrange think to make a jsonrpc server.

Now i see that my mistake was that i dont see in the server code the default post endpoint, so i was trying to connect directly to the ip:port without any endpoint… :blush:

I will try again ofxjsonrpc later

Thanks !!!

Super. Sorry, like many of my addons I have a lot of inline documentation, but not a lot of easy-to-read documentation :slight_smile: Good luck!

Jus tried, and of course it works :slight_smile: Thanks a lot!!

i was getting a msg in the client
Missing Content-Type header in the HTTP response

So i added:
args.getResponse().setContentType("application/json");

And works great!

Great to hear. Also, this may be fixed in the develop versions of ofxHTTP and ofxJSONRPC … but anyway, really glad to hear it’s working :slight_smile:

Cheers!