Closed HalfdanJ closed 8 years ago
Ha, I'm literally working on that right this moment. I'll ping back here in a second ...
Convenient 👍 well, learned a lot of POCO on the way :)
Good. I'm pushing it to develop momentarily ...
I just build a nice client for Google Cloud Vision (authentication was the hardest part, but I got JSON Web tokens and oauth2 in ofxHTTP now) and a few other services with it, which I'll also push to develop.
OK, check out the develop branch. You may need to make sure you're using the develop branch of the dependencies. Once you get it, check out the JSON example.
https://github.com/bakercp/ofxHTTP/blob/develop/example_basic_client_json/src/ofApp.cpp
Heh, Cloud Vision was also the thing I was working on :) Thanks for the push! Ill take a look at it
I'm using your post example, trying to post JSON to https://vision.googleapis.com/v1/images:annotate?key=<KEY>
isSuccess() returns false, but no error is printed. I beleive maybe its because i miss Content-Type: application/json
in the header?
Yeah, the post example won't work -- you have to use the json example -- which uses an ofxHTTP::JSONRequest, rather than an ofxHTTP::PostRequest underneath.
Sorry, also what i meant.. I use the code from the link
Hm ... let me take a look.
I dont know if its beacuse im missing a commit in a dependency. I couldn't find any develop branch on the other repos.
Can you ignore the issuccess and see what data is printed back to you? Also, check the response for error codes ... and also make sure you clean your project :)
Found it , invalid argument.. Will look at it (tomorrow)
Cool! Keep me posted and maybe I'll have my ofxCloudPlatform public tomorrow ...
Hey, found your bug and fixed it here: 9a4a90ae0421098f4300da96acd1aa21dd5191e2
Worked, thanks!
By the way @HalfdanJ, you can check out a working example here https://github.com/bakercp/ofxCloudPlatform.
Hey @bakercp I am trying to make a POST with a binary file on the body, like @HalfdanJ says. (like PUT's method has) I want to upload files to Firebase Storage from OF. The working post format I used in POSTMAN is working:
`
nice! solved. :) it worked like that:
std::string url = "https://firebasestorage.googleapis.com/v0/b/xxxxxx.appspot.com/o?uploadType=media&name=myFolder/myPictureObjectName";
ofx::HTTP::Client client;
ofx::HTTP::Context context;
ofx::HTTP::PostRequest postRequest(url, Poco::Net::HTTPMessage::HTTP_1_1);
postRequest.setContentType("image/png");
postRequest.addFormFile("", "filename.png");
try
{
auto response = client.execute(context, postRequest);
...
}
hmm.... sorry @bakercp for still bothering you with this, but I think sometimes it's useful to have some of your PUT methods (setPutFile, setPutBuffer...) on a POST request. Now I am trying to make a POST to the Firebase database to create a new object like this:
Saving Lists of Data
To generate a unique, timestamp-based key for every child added to a Firebase database reference we can send a POST request. For our users path, it made sense to define our own keys since each user has a unique username. But when users add blog posts to the app, we'll use a POST request to auto-generate a key for each blog post:
curl -X POST -d '{ "author": "alanisawesome", "title": "The Turing Machine" }' 'https://docs-examples.firebaseio.com/rest/saving-data/fireblog/posts.json' Our posts path now has the following data:
{ "posts": { "-JSOpn9ZC54A4P4RoqVa": { "author": "alanisawesome", "title": "The Turing Machine" } } } Notice that the key -JSOpn9ZC54A4P4RoqVa was automatically generated for us because we used a POST request. A successful request will be indicated by a 200 OK HTTP status code, and the response will contain the key of the new data that was added:
{"name":"-JSOpn9ZC54A4P4RoqVa"}
I am trying like this, but I am getting a 400 Bad Request (uncomplete message) reply:
std::string url = "https://xxxxxx.firebaseio.com/seeds.json";
ofx::HTTP::Client client;
ofx::HTTP::Context context;
ofx::HTTP::PostRequest postRequest(url, Poco::Net::HTTPMessage::HTTP_1_1);
postRequest.setContentType("text/javascript");
postRequest.addFormFile("", "file.json");
...
Am I just missing it, or does the postRequest object not support post request where i supply the raw body instead of through a form? I see the PUT request has a setPutBuffer that seems to be what I need, but that is not implemented in POST.