title: Foscam IP camera: get snapshot
body: <p>I'm trying to get a snapshot from my Foscam FI9816P camera.
  I'm using the following address:</p>
  
  <pre><code>http://[IPADDRESS]:[PORT]/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&amp;usr=[USER]&amp;pwd=[PWD]
  </code></pre>
  
  <p>and this works fine from the browser, showing the image snapshot. </p>
  
  <p>Programmatically, I've been using in the past another camera, providing the ("raw") JPG image as the response:</p>
  
  <pre><code>using (WebClient client = new WebClient())
  {
      byte[] JpgFile = null;
      JpgFile = client.DownloadData(sWebCam);
      // ...
  }
  </code></pre>
  
  <p>Now, this new camera is providing a "HTML page" as the response, containing the image link as an embedded <code>img</code> tag:</p>
  
  <pre><code>&lt;html&gt;&lt;body&gt;&lt;img src="../snapPic/Snap_20150729-164352.jpg"/&gt;&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Now, the point is that if I point to the image address:</p>
  
  <pre><code>http://[IPADDRESS]:[PORT]/snapPic/Snap_20150729-164352.jpg
  </code></pre>
  
  <p>I get a <strong>404 - Not found</strong> error.
  I can't see what is going on "behind the scenes" to get the image; above all, I don't know how to get the "raw" image JPG in C#.</p>
  
  <p><strong>Edit [1]:</strong> </p>
  
  <p>I got this working, parsing the image tag inside the html, and sending a second "GET" request:</p>
  
  <pre><code>sWebCam = String.Concat("http://", cConfig.WebcamIpAddress, "/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&amp;usr=[USER]&amp;pwd=[PWD]");
  try
  {
      JpgFile = client.DownloadData(sWebCam);
  
      string sTmp = System.Text.Encoding.Default.GetString(JpgFile);
      sTmp = sTmp.Substring(sTmp.IndexOf("&lt;img src=\"") + "&lt;img src=\"".Length);
      sTmp = sTmp.Substring(0, sTmp.IndexOf("\"/&gt;"));
      sTmp = sTmp.Replace("..", "");
  
      sWebCam = string.Concat("http://", cConfig.WebcamIpAddress, sTmp);
      JpgFile = client.DownloadData(sWebCam);
  }
  </code></pre>
  
  <p>So, i'm wondering why accessing the final image address <em>from the browser</em> (<code>http://[IPADDRESS]:[PORT]/snapPic/Snap_20150729-164352.jpg</code>) is giving out a 404. This is the original reason why I was confused...</p>