Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use this with a POST request? #20

Open
micahwalter opened this issue Aug 7, 2016 · 5 comments
Open

Is it possible to use this with a POST request? #20

micahwalter opened this issue Aug 7, 2016 · 5 comments

Comments

@micahwalter
Copy link

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

@bakercp
Copy link
Collaborator

bakercp commented Aug 8, 2016

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

@moebiussurfing
Copy link

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?

@moebiussurfing
Copy link

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

@bakercp
Copy link
Collaborator

bakercp commented Oct 20, 2017 via email

@moebiussurfing
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants