ofxHttpUtils example

Hi All,

I am new here & and a total openframeworks noob, so I hope someone can help me.
I participated in a few of Theo’s OF workshops a few years ago here in Amsterdam, but now I finally have time and a reason to use it.

i am trying to upload an image to a server with the httpUtils addon, but it is a bit over my head. There is an example somewhere here on the forum, but it refers to an older version and doesn’t work. I took a look at the source, but i don’t understand how to implement the listeners for the httpevents. So does anybody maybe have a working example for me?

Thanks!

Heerko

welcome heerko

i made the addon to be mostly about text, posting website form content and downloading text from urls etc

the most up to date addon is here
http://addons.openframeworks.cc/project-…-xhttputils

you could try posting the image as a form field, i.e. with lots of rgb values, and the php script saving the image the other end

or you could try doing it with ftp

are you trying to upload a file, or an image created at runtime with OFW?

Hi Chris,

Thanks for the reply. The image that I want to send will be relatively big, a 1600x1200 webcam image, so reconstructing it serverside might be a bit too heavy. Trying to use base64 encoding now, suppose that would be a bit more optimized on the server.
Ftp might also be an option, is there an easy way to do this in OF?

Thanks again. Heerko

Hi Chris,

First of all I’m a major lurker here but this is my first post so just wanted to say whats up to everyone. I’ve been using openFrameworks for about a year but I’ve never found a problem which someone else hadn’t had before me and gotten a solution or anything that someone else couldn’t answer better than me until now.

I’m sorta in the same boat as Heerko with the ofxHttpUtils although I’m trying to use them for more basic stuff like grabbing URLs/sending form values/etc using Poco instead of libCurl. Any chance you can post back up that example file for 0.06 you had posted back in June? The link seems to be dead.

I have everything compiling with no problems, and I understand the basics of events in oF but this is just not making sense to me really.

Thanks a million

-Steve

in setup() do this
ofxHttpEvents.addListener(this);

here is an example to POST form data in a thread to a url…

  
  
ofxHttpForm form;  
form.name = "this_is_my_form";  
form.method = OFX_HTTP_POST;  
form.action = "[http://localhost/";](http://localhost/";)  
form.addFormField("field_name", "field_value");  
ofxHttpUtil.addForm( form );  
  

if you have registered the event callback, you will get either a response, a connection error or if unlucky & in windows a crash (a long standing problem).

you need to make two functions in test app to handle those responses

  
  
void testApp::newResponse(ofxHttpResponse & response){  
    printf("new response\n");  
    printf(response.responseBody);  
}  
  

(for receiving the response)

Look at the definition of ofxHttpResponse in ofxHttpUtils for what a response object contains, but basically response.responseBody is the text that was downloaded

for errors…

  
  
void testApp::newError(string error){  
    printf("new error = %s\n", error.c_str());  
}  
  

To download text you could just POST an empty form

  
  
ofxHttpForm form;  
form.name = "emptyform";  
form.method = OFX_HTTP_POST;  
form.action = "[http://localhost/";](http://localhost/";)  
ofxHttpUtil.addForm( form );  
  

or use GET
form.method = OFX_HTTP_GET;

The above examples add the forms to a queue, the addon has a thread running that works its way through the queue, without locking up the app, is the idea.

If you don’t mind it locking up whilst downloading, getUrl() instead.

The addon is early days, and there are definitely some poco issues in windows, but let me know if you have questions / problems

Hey Chris,

Thanks a lot for this. I did run into one snag, which is where you have your responses listed as being in the test app so I assumed everything should be in the test app. After looking at the code and what the listener was looking for and seeing a previous post from you on what your code setup looked like I realized I needed to create a class that extended ofxHttpEventListener and do everything in there. After doing that everything went smoothly.

This is really great, I have been trying to use the ofScraper class with CURL, which was working in 0.05 but was a very clunky, heavy solution since all I wanted was the URL to be loaded. I have had issues even getting that working in 06 so this is a perfect solution.

Thanks again