ofxJSON
ofxJSON copied to clipboard
Is it possible to use this with a POST request?
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
That is how I would do it!
Also, basic http auth is supported in ofxHTTP as well as oauth 1/2.
On Fri, Oct 20, 2017, 10:36 AM moebiussurfing [email protected] wrote:
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
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jeffcrouse/ofxJSON/issues/20#issuecomment-338242059, or mute the thread https://github.com/notifications/unsubscribe-auth/AASVxBQN8VI-VOqeKRvG4wgeSmnDSFAGks5suL3ygaJpZM4Jem1S .
cool! thanks. should I use the master branch to use the oauth? now I am using 0.9.8 with the stable branch.