Main Site Documentation

User and password for HTTP GET


#1

How to send a HTTP GET for a web page that requires username and password?

I have tried using the HttpHelper

HttpHelper.CreateHttpGetRequest(“http://username:password@ IP/homepage/callAction?deviceID=10&name=turnOn”);

But it does not work.


#2

Thank you.

I dont really know how to answer that.

It returns this error when not using username/password: HTTP/1.1 401 Unauthorized

It is a Fibaro Home Center Light, that i am trying to talk to.


#3

Hello,
It seems that your server is using basic authentication (response is HTTP/1.1 401 Unauthorized according to RFC 2616).

Try again by adding the following HTTP header section to your request.

NAME: Authorization
VALUE: Basic {your credentials in base 64 encoded format}

for instance, if your credentials are:

UserName: Elmstrom
Password: Elmstrom

your credentials in plain text will be:

Elmstrom:Elmstrom

your credentials in the required base 64 format will be:

RWxtc3Ryb206RWxtc3Ryb20=

now add the following header section to your HTTP client request:

httpclient.Headers.Add(“Authorization”, “Basic RWxtc3Ryb206RWxtc3Ryb20=”);

httpclient.SendTo(“your web server’s URI”);

Don’t forget to encode in base 64 your real UserName:Password pair before trying.

Hope this helps!


#4

The way you are sending it is proper for plaintext HTTP Authentication.

I did a little googling, and found some info on this device. Across the board, members quote the documentation to be out of date, etc. On a separate support forum, I have found a different command syntax than what you describe (The post was from Oct. 2013 and is the newest information I can find):

"Control over HTTP

Version 1037 software introduces HC2 can communicate with headquarters via
HTTP messages. Simple integration over HTTP (without user authentication and checking
permissions) can be activated in the section Configuration."

Syntax:
“http://HC2_IP/Fibaro/externalRequest.php?setBinaryLight&deviceID=10&name=turnOn”

However, I have also seen the call being issued on /api/ and not /Fibaro/ . Even within the community to this particular device there is some inconsistencies between “accepted” and “documented” syntax.


#5

Thanks for the reply’s.

I will try to look at your way HABOT.

I should have mentioned that the commands works fine when sent from firefox or chrome. And when HTTP commands are sendt to servers without username/password it also works fine.

So i narrowed it down to the authentication.


#6

It worked, thanks alot HABOT

Here is what i ended up with:

             
var req = HttpHelper.CreateHttpGetRequest("http://0.0.0.0/api/callAction?deviceID=10&name=turnOn");
req.AddHeaderField("Authorization", "Basic RWxtc3Ryb206RWxtc3Ryb20=");
req.SendRequest();


#7

you’re welcome pal.


#8

And HABOT, let me welcome you again to the community. Great to see someone new adding to the collective knowledge !