Pages: [1]   Go Down
Author Topic: How to access a WebServer with login by a WebClient  (Read 1147 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I want to access a WebServer (Camera IP) with login by a Arduino-WebClient, but I dont know how do it.
I have tried this code on Arduino-WebServer:

if (client.connect(server, 81)) {
    Serial.println("connected");
    // Make a HTTP request:
    //client.println("GET /search?q=arduino HTTP/1.1");
    client.println("GET /myusername:mypassword HTTP/1.1");
    //client.println("Host: www.google.com");
    client.println("Host: IPCamera_Web");
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }


My WebCamIP response this:

HTTP/1.1 401 Unauthorized
Server: IPCamera-Web
Date: Fri Jul 26 23:50:13 2013
WWW-Authenticate: Basic realm="IPCamera_Web"
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html

<html><head><title>Document Error: Unauthorized</title></head>
      <body><h2>Access Error: Unauthorized</h2>
      <p>Access to this document requires a User ID</p></body></html>


How I can get authorization of my WebCamIP, with Arduino, please!
Thank you in advance!
Best regards,

AJoao
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8653
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From http://en.wikipedia.org/wiki/Basic_access_authentication

When the user agent wants to send the server authentication credentials it may use the Authorization header.

The Authorization header is constructed as follows:

Username and password are combined into a string "username:password"
The resulting string literal is then encoded using Base64
The authorization method and a space i.e. "Basic " is then put before the encoded string.

For example, if the user agent uses 'Aladdin' as the username and 'open sesame' as the password then the header is formed as follows:

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==


You can learn about Base64 here: http://en.wikipedia.org/wiki/Base64
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi johnwasser,
I have tried to program my Arduino-WebClient again, after your post, but I cant access to my WebCam yet.
I have see these links:
Link to converter online: http://www.motobit.com/util/base64-decoder-encoder.asp
http://en.wikipedia.org/wiki/Basic_access_authentication#Client_side
http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html
http://www.httpwatch.com/httpgallery/authentication

Part of my Arduino-WebClient code is:
if (client.connect(server, 81)) {
    Serial.println("connected");
    // Make a HTTP request:
    //client.println("GET /username:pass HTTP/1.1");  // ???
    client.println("GET /username/pass HTTP/1.1");     // ???
   
    client.println("Host: 192.168.1.244");
    //client.println("Host: IPCamera_Web");
   
    client.println("Authorization: Basic dXNlcm5hbWU6cGFzcw==");
   
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }

The WebCam response:
HTTP/1.1 403 Forbidden
Server: IPCamera-Web
Date: Sat Jul 27 12:53:53 2013
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html

<html><head><title>Document Error: Forbidden</title></head>
      <body><h2>Access Error: Forbidden</h2>
      <p>Access Denied
Prohibited User</p></body></html>


I dont know here is my bug!!!
Somebody can help me, please!
Thank you in advance!
Best regards,

Ajoao

AJoao

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8653
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What exact URL do you use to connect to your webcam with a browser?  Does it work from the browser if you put 'username:pass@' in front of the address?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You may need to search Google for the make of your web cam to see if there is detailed info on its operation or a user's manual. Make sure you are doing the base64 encoding properly like below (the bottom links have encode and decode for checking). I use something similar to update my no-ip account.


myusername:mypassword

bXl1c2VybmFtZTpteXBhc3N3b3Jk

http://www.opinionatedgeek.com/dotnet/tools/base64encode/

http://www.opinionatedgeek.com/DotNet/Tools/Base64Decode/default.aspx

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
thank you everybody by to dispend your time with me!
Hi already did find a solution for my project. It is the following:
On Chrome:
http://username:pass@192.168.1.244:81/video/livesp.asp. It is Ok!
On Firefox it is necessary to confirm the login.
On IE dont work!

On Arduino-WebClient:
Serial.println("connected");
    // Make a HTTP request:
    client.print("GET /Authorization: Basic ");
    client.print("dXNlcm5hbWU6cGFzcw==@192.168.1.244:81");
    client.println("/video/livesp.asp HTTP/1.1");
    client.println("Host: IPCamera_Web");
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }


It is OK!
See this link: http://www.httpwatch.com/httpgallery/authentication
And this link to converter Base64 online: http://www.motobit.com/util/base64-decoder-encoder.asp
See this link too: http://en.wikipedia.org/wiki/Basic_access_authentication#Client_side

But my project dont is complete yet! But already it is a begin...
I will go to thinging about that...
Best regards,

AJoao
Logged

Pages: [1]   Go Up
Jump to: