Android Question Set Host Value in HttpJob PostString

zabayin

Member
Licensed User
This is my working code that grab the token from server when I comment out "Host" in line 11.
In postman , I Have to Be checked the Host Header to work OR i get 401 unauthorized. of course.
I searched httpjob posts in forums and not found about Host Header Method.
How to Send Host Value with GetRequest.Host("Host","") '< --------------- something like this.

Here is my working code and i attached pic.
Thank you for reading.

B4X:
Sub GetTokenAndSavetoPhone As ResumableSub
        
    Dim job As HttpJob
    Dim url As String = "https://tel.com/auth/realms/eis/protocol/openid-connect/token"
    job.Initialize("", Me)
    job.PostString(url, "grant_type=client_credentials")
    
    job.GetRequest.SetHeader("Authorization", "Basic " & passbasekey)   
    job.GetRequest.SetContentType("application/x-www-form-urlencoded")   
    
    job.GetRequest.SetHeader("Host","")   
    
        
    Wait For (job) JobDone(job As HttpJob)
    If job.Success Then
                
    
        Log(job.GetString)
        
        'Parse
        Dim JSON As JSONParser
        Dim Map1 As Map
        JSON.Initialize(job.GetString)
        Map1 = JSON.NextObject
        
        Dim access_token As String = Map1.Get("access_token")
        
        Log(access_token)
        
        'Writer Text
        File.WriteString(File.DirInternal, "l7token.txt", access_token)
        
        
        
        
        job.Release
        Return True
    
    Else
        
        job.Release
        Return False
    
    End If
            
            
        
    
End Sub





I need to set header with Host value. but i dont' know how to set.
Thank you.
 

Attachments

  • mt.png
    mt.png
    141.3 KB · Views: 156
Top