in reply to Web service called with wrong parameter

I assume you've tested that $photo is what you expect it to be?

What do you get in $imgfile? Have you looked at $res->is_success or $res->code? (just dumping the whole $res object is a useful debugging aid).

My guess would be that you need to tell the backend what types of image files you will take, eg $ua->default_header('Accept' => 'image/jpeg')

As Corion says. open the debugger in your browser, and look to see which headers the browser sends/gets when you ask it to get that image URL