Android Question httpjob post creates error before access (in log plesk)

scsjc

Well-Known Member
Licensed User
Longtime User
Hi, I have a protected folder that I enter with a simple post, and it works correctly whith this simple code:


B4X:
                    Dim job1 As HttpJob
                    job1.Initialize("1", Me)
                    job1.PostString("https://xxxxx.php", "a=1234&b=22222")
                    job1.Username = "username"
                    job1.Password = "password"


the problem is that check the log of "SSL / TLS ACCESS to Apache" I have seen that an error is always created before access (this screen is from plesk)


upload_2019-11-7_10-4-20.png



I don't know if the error is due to the fact that I have to put some header in HTTPJOB.
I don't know if this is the most correct place to do the query.
Thanks !!!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is the standard way that authentication is made. The first request doesn't include any authorization header*.
The server responds with 401 code and depending on the authentication method it can include more information. The client then sends another request with the authorization header.

* If the request cannot be reproduced then the authorization header will be sent on the first request. This happens when the request is initialized with an input stream.
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
This is the standard way that authentication is made. The first request doesn't include any authorization header*.
The server responds with 401 code and depending on the authentication method it can include more information. The client then sends another request with the authorization header.

* If the request cannot be reproduced then the authorization header will be sent on the first request. This happens when the request is initialized with an input stream.

Thank you very much for your clarification;) "every day you learn something new"

I was simply reviewing and optimizing the application and I found this, and I don't have much knowledge about this.
The important thing for me is that it is something normal and verified by a professional like you :)
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
This is the standard way that authentication is made. The first request doesn't include any authorization header*.
The server responds with 401 code and depending on the authentication method it can include more information. The client then sends another request with the authorization header.

* If the request cannot be reproduced then the authorization header will be sent on the first request. This happens when the request is initialized with an input stream.

Can the system be optimized with only 1 request?
Force the first request to have a header?

Outside the standard is there any way, that the request is not sent first without a header? that is to say, the first request is with a header to authenticate the first time (not the second)

I don't know much how the request post works, and I don't know if some delay is generated when sending the request twice?
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
This is the standard way that authentication is made. The first request doesn't include any authorization header*.
The server responds with 401 code and depending on the authentication method it can include more information. The client then sends another request with the authorization header.

* If the request cannot be reproduced then the authorization header will be sent on the first request. This happens when the request is initialized with an input stream.

Forget last answer....

i use setheader to put user and password and work at 1rst time request.

B4X:
j.GetRequest.SetHeader("Authorization", "Basic " & codigo.encode64(username & ":" & password))

thanks ;)
 
Upvote 0
Top