Reputation: 33
I'm working with a stm32f4 microcontroller using lwip/stack, i use it to controle send http requests via ethernet . the following code works fine:
sprintf(buffer, "GET /api/callAction?deviceID=80&name=turnOn\r\n");
strcat(buffer, "Host: 192.168.2.7\r\n");
strcat(buffer, "Connection: close\r\n");
strcat(buffer, "\r\n");
the problem is when the sever needs authentication like this :
admin:[email protected]/api/callAction?deviceID=80&name=turnOn
i have tried adding an authorization part to the code :
strcat(buffer, "Host: admin:[email protected]\r\n");
But the http request doesn't work .
Any ideas? ps: im using Keil ARM /stm32f4 / lwip stack Server: Fibaro home center lite
Upvotes: 1
Views: 1680
Reputation: 11638
Have a read here:
https://en.wikipedia.org/wiki/Basic_access_authentication
you want to pass this string
Authorization: Basic XXXXXXXXXXXXXXXX
where XXXXXXXXXXXXXXXX is the Base64 version of username:password
for example, if username is Aladdin
and password is OpenSesame
then you have to Base64 encode the string Aladdin:OpenSesame
which results into QWxhZGRpbjpPcGVuU2VzYW1l
you string is then:
Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l
Just strcat it as you do for all the other stuff:
strcat(buffer, "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l\r\n");
Upvotes: 1