B4R Question httpjob GET request

Status
Not open for further replies.

AndroidMadhu

Active 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....
B4X:
#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
 

AndroidMadhu

Active Member
Licensed User
B4X:
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, 0, Min(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("https://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

B4X:
Connected to router.
*******************************
JobName: Example
ErrorMessage: Failed to connect
Status: 0
:
 
Upvote 0

AndroidMadhu

Active 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 :

B4X:
http://mypage.com/addTemperature.php?temperature=13.7&humidity=16.7
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Did you test the page by a normal browser
Yes...
Below is my code
B4X:
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?
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Uncomment the first dowload statement and comment the if in jobdone.
This is working like a Magic...... Very happy today....
Just one more question....I am getting the below details when it is starting...
B4X:
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?
 
Upvote 0
Status
Not open for further replies.
Top