Android Question httputils2 Bad Request and Not Found

hung

Active Member
Licensed User
Longtime User
My code is simple as below:

B4X:
Sub submit(url As String, parm As String, jobname As String)
    Dim job1 As HttpJob
   
    job1.Initialize(jobname, Me)
    job1.PostString(url, parm)
    job1.GetRequest.Timeout = 10000
End Sub
 
Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        Select Job.JobName
            Case "job1", "job2"
                ToastMessageShow("Done: " & Job.JobName, False)
        End Select
    Else
        ToastMessageShow("Error: " & Job.JobName &":" & Job.ErrorMessage, False)
       
    End If
    Job.Release
End Sub

I call the "Submit" program with two url with same html file but in two different servers. I found the following error:
1. The program can acces url from server 1 without problem. Message "Done"
2. The program failed to access url from server 2 with error mesages as below
- if use wifi, error message said "Bad Request"
- if use gprs, error message said "Not Found"
3. I load the same url from server 2 into webview, no problem

I browsed thrugh the "bad request" posts but cannot find solution. Any suggestions?
 

hung

Active Member
Licensed User
Longtime User
That works. Thank you Erel.

I updated my code as below then it works. I got the "user-agent" from server side then load with Webview to see the "User-Agent" from my phone.

Sub submit(url As String, parm As String, jobname As String)
Dim job1 As HttpJob
job1.Initialize(jobname, Me)
job1.PostString(url, parm)
job1.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Linux; Android 4.2.2; zh-cn; X909 Build/JDQ39) AppleWebKit/534.30(KHTML,like Gecko) Version/4.0 Mobile Safari/534.30")
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…