Android Question Login Using API

Sanil Kumar

New Member
Licensed User
Hi,
I am a beginner in B4A and not familiar with web services.
I want to login to my App by using an API(connection to my MySql database) ,How can I Authorize that API in my B4A coding page.
May i know how to add into the Header the following
- Basic authorization
- Username, password
-Get Method

Please let me know more about this QUERY.
Thank You
 
Last edited:

mcqueccu

Well-Known Member
Licensed User
Longtime User
Hello @Sanil Kumar Welcome to B4X.

One thing that works is the search. There are tons of example about your topic. Look for okhttputils

Also, in future, when posting a question, adding a little bit of code can help us know how best we can help you.
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
B4X:
'Note: ADD okhttputils library

    Dim job As HttpJob
    job.Initialize("job",Me)
    job.Username = "your username here"
    job.Password = "your password here"
    job.Download("your api url here")


For other types of authorization you can set them in header like this


B4X:
job.GetRequest.SetContentType("application/json")
job.GetRequest.SetHeader("Authorization", "Basic " & credentials)
job.GetRequest.SetHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36")
'
 
Last edited:
Upvote 0

Brandsum

Well-Known Member
Licensed User
Hi,
I am a beginner in B4A and not familiar with web services.
I want to login to my App by using an API(connection to my MySql database) ,How can I Authorize that API in my B4A coding page.
May i know how to add into the Header the following
- Basic authorization
- Username, password
-Get Method

Please let me know more about this QUERY.
Thank You
  1. Add two text field one is for username and another is for password and also a button for submitting
  2. On button click store both value to PostData variable
  3. Always POST sensitive information. Dont use download method.
  4. In the backend check if username and password is correct or not.
  5. If not, send error message (echo if you are using php), which you can retrieve from j.GetString method in B4A.
  6. If credentials are correct then generate a token usually a random string, store it for the respective user in the database and send back to the app.
  7. Store it to starter service so that you can further send it to the server for authentication.
  8. Next for every request you can either send this token to the server via post method or you can set it to the header as @mcqueccu wrote.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
.So I request you to please attach one example ( using API).
USE the forumsearch! There are plenty of examples. Do NOT expect us to do YOUR work.

One example:
 
Upvote 0
Top