jeffcrouse/ofxJSON

Is it possible to use this with a POST request?

micahwalter opened this issue · 5 comments

I was looking at openRemote and it looks like it can only handle GET requests.

https://github.com/jefftimesten/ofxJSON/blob/master/src/ofxJSONElement.cpp#L70

I was wondering if its possible to use this for POSTs as well?

-cheers,
micah

This uses the built-in ofLoadURL which defaults to GET requests. You can construct a similar POST request using the underlying Poco::HTTPRequest or you can use ofxHTTP which has support for POST requests, JSON post requests, etc. See this example:

https://github.com/bakercp/ofxHTTP/blob/develop/example_basic_client_post/src/ofApp.cpp

or

https://github.com/bakercp/ofxHTTP/blob/develop/example_basic_client_post_json/src/ofApp.cpp

hey @bakercp , any chance to get this POST JSON sample ? (404)
i want to use this to use with a Django server with a custom REST API...
any help?

just solved, (I think) it worked doing this:

std::string url = "https://test1.io/writejson/";
    
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
putRequest.setPutFile("file.json");
putRequest.setContentType("text/javascript");
...
// post
std::istream& responseStream = client.execute(postRequest,
                                                      response,
                                                      context);

Now I am looking to handle a user/pass login system for the API REST, maybe something like oAuth

cool! thanks. should I use the master branch to use the oauth? now I am using 0.9.8 with the stable branch.