Mike Weber Mike Weber - 2 years ago 120
Objective-C Question

web cam image from url using objective-c

I am writing an OS X app, with cocoa, and trying to figure out how to get a web-cam still image
from an axiscam at this url:


Using the dispatch/queue/block suggested here:

Getting Image from URL Objective C

it will return the html code of the page.

What is the suggested way to get the image data from the web-cam and not the page?
Since there isn't a direct link to a jpg image, it is a bit confusing.

I was able to make this work in C# - Save Webcam Image From Website
which is my answer/question at the bottom - looks like I forgot my old accnt and started a new one.

Answer Source

Looks like I figured this out.

Headers need to be set up as follows:

self.bweHeader = @"http://bigwatersedge.axiscam.net/view/snapshot.shtml?picturepath=/jpg/image.jpg?timestamp=";
self.bweImage = @"http://bigwatersedge.axiscam.net/jpg/image.jpg?timestamp=";
self.bweHost = @"bigwatersedge.axiscam.net";

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL       URLWithString:[self.bweImage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];

[theRequest setHTTPMethod:@"GET"];
[theRequest addValue:self.bweHost forHTTPHeaderField:@"Host"];
[theRequest addValue:self.bweHeader forHTTPHeaderField:@"Referer"];

NSData *data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&returnError];

NSImage *camImage = [[NSImage alloc] initWithData:data];

[self.imageView setImage:camImage];
[self.imageView setImageScaling:NSImageScaleProportionallyUpOrDown];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download