This below is the code that I have trying to capture the Wanscam ip camera however does not work now is raising some exceptions and does at all and I really do not know whats going on
The remote server returned an error: (401) Unauthorized. sometimes this is the exception but many times does not even know what kind exception happened.
Please anyone can spot something, since now thank you all.
there is just a button in the form, and as long this button display Stop the loop will go around updating the picture box.
and the camera is a Wanscam AJ-C2WA-C198 I know this is not the greatest camera in the world.
and my admin name and my password are match right.
EDIT:: I notice that on VLC I see that image after I enter the admin and password again but I already did on the URL that is weird
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace cam01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Thread _cameraThread;
private string metaUrl = "http://home-ip-camera.dyndns-server.com/videostream.asf?user=<USER_NAME>&pwd=<PASSWORD>resolution=64&rate=0";
public HttpWebRequest req;
public WebResponse res;
public System.IO.Stream stream;
private void button1_Click(object sender, EventArgs e)
{
if (btnMain.Text.Equals("Start"))
{
if (_cameraThread == null)
_cameraThread = new Thread(new ThreadStart(Run));
_cameraThread.Start();
btnMain.Text = "Stop";
}
else
{
btnMain.Text = "Start";
_cameraThread.Abort();
_cameraThread = null;
}
}
private void Run()
{
while (btnMain.Text.Equals("Stop"))
{
try
{
req = (HttpWebRequest)HttpWebRequest.Create(metaUrl);
req.AllowWriteStreamBuffering = true;
req.Timeout = 20000;
res = req.GetResponse();
stream = res.GetResponseStream();
pictureBox1.Image = Image.FromStream(stream);
res.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e.ToString());
}
}
}
}
}
`
You can check, that http port are setted correct. (Route on your DDNS or specify in get-query). By default port is 99, not 80!
Also, you can try to use /videostream.cgi?user=<USENAME>&pwd=<PASSWORD>
- it get you MJPEG stream instead FFMPEG, provided by videostream.asf
Finally, try to specify creditals in your request:
req.Credentials = new NetworkCredential("<USENAME>", "<PASSWORD>");
and try another query params: loginuse=<USENAME>&loginpass=<PASSWORD>