There is a website that posts a image from their webcam that I would like to be able to grab using a program. How woul开发者_如何学JAVAd I get this jpeg data in memory? I have tried HttpRequest but it only returns html.
Here is the link:
http://bigwatersedge.axiscam.net/view/snapshot.shtml?picturepath=/jpg/image.jpg
Image source is at this URL:
http://bigwatersedge.axiscam.net/jpg/image.jpg?timestamp=
Use WebClient to save the data.
WebCleint wc = new WebClient();
byte[] data = wc.DownloadData("http://bigwatersedge.axiscam.net/jpg/image.jpg?timestamp=");
The URL of the image is actually http://bigwatersedge.axiscam.net/jpg/image.jpg?timestamp=. The URL you gave returns a page with an image on it.
Now, once you are downloading the correct URL of the image, this particular server is checking your HTTP referer. Put this in your HTTP headers:
Referer: http://bigwatersedge.axiscam.net/view/snapshot.shtml?picturepath=/jpg/image.jpg
I am working with Robert, the original poster on this, and have a problem getting to that URL with the image. If the URL is pasted in the browser:
403 Forbidden Your client does not have permission to get Images/Streams from this server.
Which is new, I was getting the URL text repeated in the browser:
http://bigwatersedge.axiscam.net/jpg/image.jpg?timestamp=
WebClient throws and exception: "The underlying connection was closed: The connection was closed unexpectedly."
I also added:
WebHeaderCollection headerCollection = new WebHeaderCollection();
headerCollection.Add("http://bigwatersedge.axiscam.net/view/snapshot.shtml?picturepath=/jpg/image.jpg");
wc.Headers = headerCollection;
Basically, I am having trouble retrieving the image in the URL.
update: I added the HttpRequestHeader.Referer to the header collection. No exception throw, collects the image data. Have not converted the byte array to a workable image object yet.
精彩评论