iOS Question Why does b4i refuse to establish connection to MySql server?

Status
Not open for further replies.

jkhazraji

Active Member
Licensed User
Longtime User
Why does b4i refuse to establish connection to MySql server? whether remote one or local host, by using the iHttp and iHttpUtils libraries?
..what is wrong?

B4X:
Process_Globals
.
.
.

Dim iJob As HttpJob
End Sub

Sub connect()
.
.
iJob.Initialize("MyJob",Me)
.
.
  
  iJob.Download2("https://192.168.0.21/DBDir/phpfile.php",Array As String( "key1","val1",  "key2","val1","key3","val3") )
    iJob.GetRequest.SetContentType("text/plain")
End sub

Sub JobDone(Job as HttpJob)
 
    If Job.Success Then

    Dim res As String
     res = Job.GetString
    Dim parser As JSONParser
    parser.Initialize(res)
    Select Job.JobName
            Case "MyJob"
             Dim NAMES As List= parser.NextArray 'returns a list with maps
                For i = 0 To NAMES.Size - 1
                    Dim m As Map
                    m = NAMES.Get(i)
           
             '.....
           log(m.Get("index"))
             Next
   End Select
    Else
        Log("Error ocurred:" & Job.ErrorMessage)
        
    End If
    Job.Release
 .
 .

End Sub
 

imbault

Well-Known Member
Licensed User
Longtime User
Your code doesn't show your issue with your DB, just show a call to your php web service or something like that...
Hard to help you
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Your code doesn't show your issue with your DB, just show a call to your php web service or something like that...
Hard to help you
Thanks for your reply @imbault
I am making a GET request to the phpfile.php. As the following in a web broswer:
localhost/dir/phpfile.php?key1=val1&key2=val2&key3=val3
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
You may have a typo either in your program or your example line for accessing it with the browser:

localhost/dir/phpfile.php?key1=val1&key2=val2&key3=val3

/DBDir/phpfile.php vs /dir/phpfile.php

1) If it is in the program, then change that first and see what happens.
2) If it is in the browser line (and we assume here the program URL is the correct one), then what error is logged with
B4X:
Log("Error ocurred:" & Job.ErrorMessage)

To re-iterate what @imbault said, you are not accessing MySQL with your program, you are accessing a PHP script that may be accessing a MySQL DB in the background.
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
1. I am accessing MySql through the php file from inside the program by the use of WAMP localhost server on windows 10.
2. I managed to have successful connection by the same method using b4a.
3.
B4X:
Log("Error ocurred:" & Job.ErrorMessage)
gave the error: 'unknown error, code 0'.
4. I mentioned 'localhost/dir/phpfile.php?key1=val1&key2=val2&key3=val3' just as an example of web browser.
5. I made sure I do not have any typo.
With all of that mentioned, I can not access the DB by establishing connection with MySql through iHttpUtils and iHttp of B4i.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Why are you setting the content type of the GET request?
It makes no difference..I commented the following line, but no response:(
B4X:
'iJob.GetRequest.SetContentType("text/plain")
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Just noticed the https. Is the server properly set up? If not, it could be that iOS is bouncing your connection. iOS is a lot stricter in that regard.
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Just noticed the https. Is the server properly set up? If not, it could be that iOS is bouncing your connection. iOS is a lot stricter in that regard.
I noticed it as well and corrected it to http:// but to no avail
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Silly question(s): is your phone on the same network? Is its IP address in the same network as the server you're trying to reach? Can you, on the same device, access the site via Safari?
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Silly question(s): is your phone on the same network? Is its IP address in the same network as the server you're trying to reach? Can you, on the same device, access the site via Safari?
Yes for all.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Ok try https://httpbin.org/get as the URL and see if you can get a job success. Just modify the code to log a success or failure. Before that could try to "clean" the project and re-run it as is before changing code. Are you using the bridge or how are you installing the app, just curious.
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
Can you post the logs?

Try to disable ATS:
B4X:
#ATSEnabled: False
If I connect to local host the log error message is: unknown error
If to a remote server, it tells me that it is unsecured connection and not allowed by the app policy
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
I disabled the App Transport Security
B4X:
#ATSEnabled: False
Although, It did not work
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If I connect to local host the log error message is: unknown error
How can you connect to the local host? The local host is the iPhone itself.

If to a remote server, it tells me that it is unsecured connection and not allowed by the app policy
Disabling ATS will solve it.
 
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
If I enable SSL on my remote server, will it work?
How can you connect to the local host? The local host is the iPhone itself.

Disabling ATS will solve it.
I mean a PC Windows localhost by activating WAMP program. On this server the MySql DB resides.
It did not.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

jkhazraji

Active Member
Licensed User
Longtime User
I was able to operate the same code on b4a without any errors.
First, on the address : 192.168.0.21:80 activating localhost
Then I initialized a HttpJob(MyJob) and used it as
B4X:
 MyJob.Download("http://192.168.0.21/MyChatApp/server.php?message=getdata&sender=&recep=") 
'Or 
MyJob.Download("http://www.mysite.com/MyChatApp/server.php?message=getdata&sender=&recep=")
from inside b4a
and it worked fine
but the same code after suitable modification did not work in b4i.
 

Attachments

  • wamp.png
    wamp.png
    18.6 KB · Views: 304
Upvote 0
Status
Not open for further replies.
Top