Remote connection getting closed - hitting an arbitary URL?


I’m trying to put together a project that on certain events will hit a URL with some parameters that will set various commands on a WebCam.

A made up example would be something like: http:///camera_control.cgi?user=user&password=password&command=

This works fine in a browser, but I’m having a little trouble getting this to work with the ethernet shield.

The program connects fine and the following is output:

HTTP/1.1 401 Unauthorized
Server: Netwave IP Camera
Date: Wed, 01 Feb 2012 21:37:37 GMT
WWW-Authenticate: Basic realm=“ipcamera_000DC5D34ADE”
Content-Type: text/html
Content-Length: 140
Connection: close

401 Unauthorized

401 Unauthorized

Authorization required.

after which the connection is closed (from the WebCam side I’d imagine), which means I’m unable to do the next step and execute the actual command.

Note that I’m able to connect to google etc just fine and execute commands.

I guess the WebCam is prevent the type of connection that the Arduino board is attempting (its not an HTTPS connection) - is there an alternative way to hit arbitrary URLs without first making a connection?

As a temporary workaround I’m going to setup a script on a server that the Ethernet board can connect to, which will in turn trigger the webcam command.

Any ideas would be much appreciated!


Looks like the web server is expecting a username and password. I’m guessing that you entered that data in your browser the first time you connected to the camera and your browser remembers your login information. The URL syntax is:


Hi John,

Thanks for your response.

The camera does indeed require basic authentication, which I can workaround via the browser as you say, but the problem I have is that I cant get that far as the process fails shortly after the following code:

if(client.connect(camera, 80)>0) {

It connects, but then outputs the 401 error above. I agree that it expects authentication, I'm just at a loss on how to provide it via Arduino !


Send all after the host () in the GET part of the header.

client.write("GET /camera_control.cgi?user=user&password=password&command=<command> HTTP/1.0\r\n\r\n");

Insure there are no illegal characters (like spaces) in any of that. Otherwise, you will need to url encode it.

You need to send BasicAuth header(s) - check out the relevant RFC on HTTP protocol.

Thanks, MarkT. I missed that. That is for the user:password sent in the server? Like

If so, I will remember to add that to my responses. :)

Your authentication should look something like this:

"GET /camera_control.cgi?user=user&password=password&command=<command> HTTP/1.0\r\n"
"Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n"

You can use this website to encode your USERNAME:PASSWORD in base64:

For this example, “Aladdin:open sesame” has been encoded as “QWxhZGRpbjpvcGVuIHNlc2FtZQ==”.

Thanks very much everyone - what a great forum.

The problem I was actually having was that the connection would be made using

client.connect(camera, 80)

but when I attempted to control the camera (using the various authentication methods mentioned - the base64 method was something I’d tried in java and PHP, but not here - very useful, thanks!) it failed as the connection had already been closed.

The posts above however inspired me to try a different approach: instead of opening the connection and keeping it open, I’ve tried opening the connection on a given event, controlling the camera and then stopping the connection, as follows:

if(<some event>) {
  if(client.connect(camera, 80)>0) {
    client.write("GET /camera_control.cgi?param=5&value=1&user=<user>&pwd=<password> HTTP/1.0\r\n"
                     "Authorization: Basic [base64 encoding of username:password]==\r\n"

This works a treat - I guess due to either the cameras implemenation or Arduinos connections are terminated if not authenticated in a reasonable time window.

Thanks all for your useful advice!

Interesting, I've got an IP cam in a box that I could tinker with. Might also be of use with the FosCam pan/tilt setup.