system
November 10, 2012, 3:58pm
1
Hello guys,
I have a Arduino Mega, and I am trying to make a HTTP GET to do an Authorization in my server.
I am trying in this way:
// Make a HTTP request:
client.println("GET /api/fp/ HTTP/1.0\n");
client.println("Authorization: ");
client.println("Basic YmRjYzE0MDE2ZDkxNjNmNjg5MWIxYzc1NWM3YjRhNzY6RDJNQVBsTmpBRGtMWkFCaw==");
client.println();
But I am still receiving an "Not authorized" error.
How I can do this?
Thank you very much
Insure your username and password is correct and Base 64 encoded.
In the context of an HTTP transaction, basic access authentication is a method for an HTTP user agent (e.g. a web browser) to provide a user name and password when making a request. In basic HTTP authentication, a request contains a header field in the form of Authorization: Basic <credentials>, where credentials is the Base64 encoding of ID and password joined by a single colon :.
It was originally implemented by Ari Luotonen at CERN in 1993 and defined in the HTTP 1.0 specification in 1996.
It...
It looks ok to me except for that.
edit: My bad. Here is the problem. The first client.println should be client.print
client.print("Authorization: ");
client.println("Basic YmRjYzE0MDE2ZDkxNjNmNjg5MWIxYzc1NWM3YjRhNzY6RDJNQVBsTmpBRGtMWkFCaw==");
client.println();
system
November 10, 2012, 4:08pm
3
Guys,
I tried using POST e now It's ok.
Strange because in my browser I use GET.
Anyway, thank you everybody
If you want to use GET, remove the "\n" from the end of that client.println.
// Make a HTTP request:
client.println("GET /api/fp/ HTTP/1.0");
Otherwise, it interprets everything after that line as the body (POST);
system
November 10, 2012, 4:27pm
5
Hello,
Yes, all of you was correct.
Now I am using in this way:
client.println("GET /api/fp/to/calendar/23a31003d6d904c81a3c77f62185db9c/eventos HTTP/1.0");
client.println("Authorization: Basic YmRjYzE0MDE2ZDkxNjNmNjg5MWIxYzc1NWM3YjRhNzY6RDJNQVBsTmpBRGtMWkFCaw==");
And It is working perfect
edit: I just have one more question. Why when I use HTTP/1.1 I receive a Bad Request?
And when I send a HTTP/1.0 the answer comes in HTTP/1.1
Some servers require a "Connection: close" in the header for HTTP/1.1. Replace the final client.println() with this:
client.println("Connection: close\r\n");
system
November 10, 2012, 6:19pm
7
Hello,
For tell the truth the Connection: close, didn't solve my problem.
So I searched in the google and I figured out, that I have to put the Host, like this:
client.println("GET /api/fp/ HTTP/1.1");
client.println("Host: 10.9.9.11");
client.println("Authorization: Basic YmRjYzE0MDE2ZDkxNjNmNjg5MWIxYzc1NWM3YjRhNzY6RDJNQVBsTmpBRGtMWkFCaw==");
client.println();
And now the HTTP/1.1 It's working perfectly, thank you all guys for the answers.
So, I am an absolute beginner in C++ and Arduino.
Now I have a another question, when I send the request above I receive this answer from my server:
HTTP/1.1 200 OK
Date: Sat, 10 Nov 2012 18:16:48 GMT
Server: Apache
X-Powered-By: PHP/5.3.3-7+squeeze14
Set-Cookie: PHPSESSID=v7kqmfqtd7tlpe8nk8h6kc2jc5; path=/
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Content-Length: 140
Content-Type: application/json
{"request":{"type":"GET","elapsed_time":"0.0093"},"data":{"id":"v7kqmfqtd7tlpe8nk8h6kc2jc5","name":"PHPSESSID","msg":"Auth Successfull."}}
So, now I need to use this "PHPSESSID=v7kqmfqtd7tlpe8nk8h6kc2jc5" to stay sending request to my server. How I can get this PHPSESSID from the answer and put again in my Arduino code?
Thank you very much!
Just what I was looking for! Tinkering around a couple of evenings now, finding out what the correct syntax for the Authorization: Basic header should be.
Success finally, putting the Authorization: Basic after the Host.