1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

B4R Question httpjob GET request

Discussion in 'B4R Questions' started by AndroidMadhu, Jun 11, 2019.

Thread Status:
Not open for further replies.
  1. AndroidMadhu

    AndroidMadhu Member Licensed User

    Hi,
    I am trying a different way to send the request to my webpage by using httpjob module.
    But unfortunately I am able to connect wifi [nodemcu] but still NOT able to send request to mypage.com ;)
    A simple code I am running....
    Code:
    #Region Project Attributes
        
    #AutoFlushLogs: True
        
    #CheckArrayBounds: True
        
    #StackBufferSize: 300
    #End Region

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'Public variables can be accessed from all modules.
        Public Serial1 As Serial
        
    Dim wifi As ESP8266WiFi
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        wifi.Connect2(
    "MADHU","xxxx")
        
    Log("Connected Router")
        
    HttpJob.Initialize("Sendtestrequest")
        
    HttpJob.Download("www.mypage.com/addTemperature.php?temperature=13.7&humidity=16.7")   <----This is for GET request
       
    End Sub

    Sub JobDone (Job As JobResult)
        
    If Job.Success Then
        
    Log("JobStatus :",Job.Status)
        
    Log(Job.Response)
        
    End If
    End Sub
    Any mistake I am doing? I hv ran the example from Erel.. There is also not working
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    I will try to help you one last time.

    Please upload the project where the only change you made is related to the router settings.
    And post the logs.
     
  3. tigrot

    tigrot Well-Known Member Licensed User

    You don't make a log in case of job.success=false, do and see why it fails!
     
  4. AndroidMadhu

    AndroidMadhu Member Licensed User

    Code:
    Sub Process_Globals
        
    Public Serial1 As Serial
        
    Private wifi As ESP8266WiFi
    End Sub

    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        
    If wifi.Connect2("MADHU","xxxxxxxx"Then
            
    Log("Connected to router.")
        
    Else
            
    Log("Failed to connect to router.")
            
    Return
        
    End If
        
    HttpJob.Initialize("Example")
        
    HttpJob.Download("https://www.example.com")
    End Sub


    Sub JobDone (Job As JobResult)
        
    Log("*******************************")
        
    Log("JobName: ", Job.JobName)
        
    If Job.Success Then
            
    Dim bc As ByteConverter
            
    Log("Response: ", bc.SubString2(Job.Response, 0Min(200, Job.Response.Length))) 'truncate to 200 characters
            If Job.JobName = "Example" Then
                
    'send another request
                'This time it is a POST request and we set the Content-Type header
                HttpJob.Initialize("Example2")
                
    'add headers before calling Post or Download (this is different than the standard HttpUtils2 library).
                HttpJob.AddHeader("Content-Type""application/x-www-form-urlencoded")
                
    HttpJob.Post("http://www.b4x.com/print.php?key1=value1""PostKey1=PostValue2&abc=def")
            
    End If
        
    Else
            
    Log("ErrorMessage: ", Job.ErrorMessage)
            
    Log("Status: ", Job.Status)
            
    Log(Job.Response)
        
    End If
    End Sub
    Code:
    Connected to router.
    *******************************
    JobName: Example
    ErrorMessage: Failed 
    to connect
    Status: 
    0
    :
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Good. I see this error too. Let me check it.
     
  6. AndroidMadhu

    AndroidMadhu Member Licensed User

    Thank you....
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Still checking it. It is related to a change in the underlying WiFi library behavior.
     
  8. AndroidMadhu

    AndroidMadhu Member Licensed User

    Thank you for your support......
     
  9. Erel

    Erel Administrator Staff Member Licensed User

  10. bdunkleysmith

    bdunkleysmith Active Member Licensed User

    Erel likes this.
  11. AndroidMadhu

    AndroidMadhu Member Licensed User

    The update to B4R V2.8 #Beta is working as expected. I can download successfully from mypage.com from sub AppStart

    But if I made the download from the sub JobDone, the Download is not working. could you please suggest that how Do I make a GET request using httpJob?
    As I read that link , Download to send a GET request.
    Like below :

    Code:
    http://mypage.com/addTemperature.php?temperature=13.7&humidity=16.7
     
  12. tigrot

    tigrot Well-Known Member Licensed User

    Did you test the page by a normal browser?
     
    Peter Simpson likes this.
  13. AndroidMadhu

    AndroidMadhu Member Licensed User

    Yes...
    Below is my code
    Code:
    Private Sub AppStart
        Serial1.Initialize(
    115200)
        
    Log("AppStart")
        wifi.Connect2(
    "MADHU","xxxxx")
        
    If wifi.IsConnected=True Then
            
    Log("Wifi Connected Sussessfully!!!")
        
    Else
            
    Log("Failed to connect to router")
            
    Return
        
    End If
        
    HttpJob.Initialize("TestResult")
        
    'HttpJob.Download("http://mypage.com")  ,--This is working
    End Sub

    Sub JobDone(Job As JobResult)
        
    'Dim temp As Float=11.11
        'Dim humid As Float = 22.22
        If Job.JobName="TestResult" Then
            
    HttpJob.AddHeader("Content-Type""application/text")
            
    HttpJob.Download("http://mypage.com")  <---This is not working
        
    End If
        
    Log(Job.Response) 
        
    Log(Job.ErrorMessage)
        
    Log(Job.Status)   
    End Sub
    Am I doing any mistake?
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Yes. You are not giving us enough information to help you. "It is not working" doesn't say much.
     
  15. tigrot

    tigrot Well-Known Member Licensed User

    Content-type is not taken in account for GET requests.
    In you last example Jobdone event is never fired, since there is no job running. The job is fired by method "download". Jobdone is where you must handle answers from IIS.
    Uncomment the first dowload statement and comment the if in jobdone.
     
    Johan Hormaza likes this.
  16. AndroidMadhu

    AndroidMadhu Member Licensed User

    This is working like a Magic...... Very happy today....
    Just one more question....I am getting the below details when it is starting...
    Code:
    Wifi Connected Sussessfully!!!
    ResponseCache 
    is full (100)
    ResponseCache 
    is full (36)
    ResponseCache 
    is full (100)
    ResponseCache 
    is full (100)
    ResponseCache 
    is full (100)
    ResponseCache 
    is full (72)
    ResponseCache 
    is full (8)
    Is it normal?
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for a new question.
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice