How to send as HTTP Post request as JSON in ofx?


I need to be able to send JSON in a HTTP Post request by adding a header. I have been able to do it using python, but I’d like to have it integrated in my ofx app. I’ve tried looking into ofxHTTP, but can’t seem to find a working example for setting headers and send JSON.

Do any of you have a working example or some pointers (hehe) lying around?

Best regards

I dont know about ofxHTTP but you can fairly easy do post request with libcurl.

for example:

thank you, @underdoeg! Never experimented with anything outside ofxAddons, but that was surprisingly easy. Cheers.

well, “regular” c++ programmers also try to solve stuff as easily as possible :wink:

Here’s the ofxHTTP JSON post example. It’s in the develop branch.

sorry I’m just too dumb, how can I get your ofxHTTP from develop branch working? Do I need the newest openframeworks from Github? (ofJson only appears there) And if so, is there a guide somewhere, how to set it up correctly? In my case I tried building ProjectGenerator and the libs with the provided scripts, and I end up having strange errors:

in HTTPClient.h:

std::unique_ptr<BufferedResponse> get(const std::string& uri);


Expected member name or ‘;’ after declaration specifiers
Expected ‘>’

std::string url = "";
ofx::HTTP::DefaultClient client;
ofx::HTTP::Context context;

ofx::HTTP::BaseResponse response;
ofx::HTTP::PostRequest postRequest(url, Poco::Net::HTTPMessage::HTTP_1_0);
//Passing a JSON file
// post
std::istream& responseStream = client.execute(postRequest,