Android Question HttpJob and UTF8

aedwall

Active Member
Licensed User
Longtime User
I am trying to use HttpJob to pass city names to a MySQL database, but b4A always makes funny characters out of names like "Bácum" by turning it into "B%C3%A1cum". I don't want UTF-8 conversions which I can't seem to turn back into a recognizable city name with PHP. If I tell HttpJob (job1.Download2) the city name is "Bácum", then I want it to pass "Bácum" to PHP, not "B%C3%A1cum". I have tried replacing all the references to "UTF8" in HttpJob.bas with each of these and nothing worked - "UTF-8", "US-ASCII", "Windows-1252", "ISO-8859-1".

Can someone please help me? I have spent hours on this. Thank you.

B4X:
job1.Download2("http://mydomain.com/api_atlas/atlas_b4A.php", Array As String("adm", adm, "pw", pw, "bm", the_m, "bd", the_d, "by", the_y, "hr", the_h, "mn", the_n, "city", city, "county", county, "cntry", selected_country))
 

aedwall

Active Member
Licensed User
Longtime User
>> 1. Send the data with a POST request.

Should I use something like this?

B4X:
job1.PostString("http://mydomain.com/atlas_b4A.php", Array As String("adm", "admin", "pw", "Trheé_7"))

I am trying to find a good example, but nothing so far. Thank you.

UPDATE: here is what is now apparently working:

B4X:
  xxx = "?submit=yes&adm=" & adm & "&pw=" & pw & "&bm=" & the_m & "&bd=" & the_d & "&by=" & the_y & "&hr=" & the_h & "&mn=" & the_n
xxx = xxx & "&city=" & Xcity & "&county=" & county & "&cntry=" & selected_country
        
job1.PostString("http://mydomain.com/atlas_b4A.php", xxx)


UPDATE:

And now the same code does not work. This is so frustrating. I can't understand why it works for a while, then stops working. Caching?

UPDATE:
Can someone explain to me why the POST operation is no longer working? My PHP script does not recognize any POST variables, yet it worked or else I would not have written the above note that it was working. Thank you.
 
Last edited:
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
Sure. If you show us your php script. I assume you forgot the defs of UTF8 at the beginning of the script. I use php a lot with UTF and post only. Never had an issue.

I really don't know what you mean by "I assume you forgot the defs of UTF8 at the beginning of the script." It is vague to me. I have been through so many things this weekend. It starts to work, then stops. Then starts again. I really don't have the energy now. Using POST variables instead of GET was a big help - GET is a disaster since it changes things to make it URL-friendly. I find all this character set crap such a waste of energy and time. Nothing seems to work right and you have to make special cases out of some characters. Yes, part of the problem is my own ignorance. Latin characters are not bad. But characters like "s" caron don't convert properly - or at least I don't know how to do it. I had to solve the issue with this:

B4X:
$city = str_replace("%C5%A1", "š", $city);

A city like "Abaša" comes through in various forms - AbaÅ¡a or Aba%C5%A1a or Aba?a. So I finally have a set of conditionals that tries different things and I made it work in a kludge sort of way.

I just wanted b4A to pass the name "Abaša" to a PHP $_POST["city"] command, then be able to look up that city's geographical coordinate data in a MySQL database. I pass back the data to b4A using JSON.

My complaining shows how frustrating it's been for me battling b4A, UTF-8, JSON, PHP and the rest. I am beat - late on Sunday night.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Don´t use PostString if the PHP Script is not properly configured to use the Data.

I suggest to use
B4X:
    Dim job As HttpJob
    job.Initialize("",Me)
    job.PostMultipart("Url",CreateMap("submit": "yes", "adm": adm, otherfieldshere....),Null)
    Wait For (job) JobDone(j As HttpJob)
    If j.Success Then
        'File.WriteString(File.DirRootExternal, "JobResult.txt", j.GetString)
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    j.Release
 
Last edited:
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
DonManfred said:
Don´t use PostString if the PHP Script is not properly configured to use the Data.

I have no idea what "properly configured to use the Data" means. I just want to pass a city name to MySQL, not have the city name butchered because of UTF-8 or anything else, and then return the data. When I have regained my energy (tomorrow), I will try your suggestion. Thank you for providing it.
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
did you try to decode the data in your php script?
PHP:
$city = $_POST['city'];

$city = urldecode($city);

echo $city;
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
did you try to decode the data in your php script?
PHP:
$city = $_POST['city'];

$city = urldecode($city);

echo $city;

Kijkašor gets turned into KijkaÅ¡or (by PostString) or Kijka%C5%A1or and urldecode does not return it to Kijkašor.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
Don´t use PostString if the PHP Script is not properly configured to use the Data.

I suggest to use
B4X:
    Dim job As HttpJob
    job.Initialize("",Me)
    job.PostMultipart("Url",CreateMap("submit": "yes", "adm": adm, otherfieldshere....),Null)
    Wait For (job) JobDone(j As HttpJob)
    If j.Success Then
        'File.WriteString(File.DirRootExternal, "JobResult.txt", j.GetString)
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    j.Release

This is not working for me.

B4X:
job1.PostMultipart("https://mydomain.com/atlas_b4A.php", CreateMap("adm": adm, "pw": pw, "bm": the_m, "bd": the_d, "by": the_y, "hr": the_h, "mn": the_n, "city": Xcity, "county": county, "cntry": selected_country),Null)

It reports job.Success = False

But this worked:

B4X:
    xxx = "adm=" & adm & "&pw=" & pw & "&bm=" & the_m & "&bd=" & the_d & "&by=" & the_y & "&hr=" & the_h & "&mn=" & the_n
    xxx = xxx & "&city=" & Xcity & "&county=" & county & "&cntry=" & selected_country
        
   job1.PostString("https://mydomain/atlas_b4A.php", xxx)

I will review my various books to see if there is something special about PostMultipart. It appears the "atlas_b4A.php" script is not even startin, as I log various inputs received into a debug file, and that file is not being created.

UPDATE: Now the PostStringMethod does not work - it worked last night, but now it doesn't. No code was changed. Plus, when I use the PostMultipart I see this in the log area:

upload_2019-4-29_11-57-14.png


At least I don't get a 501 error with PostString.
 
Last edited:
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
Why aren't you switching to jRDC2? It is simpler and more powerful.

Because I don't understand it and the b4A forum is difficult to navigate and find things - generally very clumsy IMO (especially the search feature). And there is no reference to it in the PennyPress pdf by Wyken Seagrave. But now since you have gone out of your way to recommend it, I will try again.

jRDC2 apparently is for b4J and so I don't know how many hoops I have to jump through to get it to work on b4A.

Oh, jRDC2 is a remote database connector. This will work fine perhaps when I interface to my atlas that is now on MySQL. But this atlas should run on its own (not via my MySQL implementation) and I want to access it directly whenever the people who make it get it to run on PHP versions greater than v5.5. My MySQL implementation is a "Doomsday" work-around until they get their act together and upgrade their product. If I didn't do this, lots of customers would now be screwed. Because of my work-around, their websites still function. So in "normal" times, the data will not get collected from a MySQL database, but from an app that will run and work on PHP 7 websites.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Because I don't understand it and the b4A forum is difficult to navigate and find things - generally very clumsy IMO (especially the search feature)
Let me try it.
https://www.b4x.com/search?query=jRDC2
Very good results. The first result is the one that you are looking for.
jRDC2 apparently is for b4J and so I don't know how many hoops I have to jump through to get it to work on b4A.
I see that you are not interested in reading the post and of course not interested in watching the video tutorial.
I will read it for you.

This is what I found:

jRDC2 is made of two components:
- B4J server. The server receives the requests from the clients, issues the SQL commands against the database and returns the results.
In many cases the server will be hosted on the same computer that hosts the database server.
- Client module. The client which is compatible with B4A, B4J and B4i is responsible for sending the requests and handling the responses.

So apparently it works with B4A, B4J and B4i...

I'm afraid that I cannot further help you.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
Let me try it.
https://www.b4x.com/search?query=jRDC2
Very good results. The first result is the one that you are looking for.

I see that you are not interested in reading the post and of course not interested in watching the video tutorial. I will read it for you.

This is what I found:

jRDC2 is made of two components:
- B4J server. The server receives the requests from the clients, issues the SQL commands against the database and returns the results.
In many cases the server will be hosted on the same computer that hosts the database server.
- Client module. The client which is compatible with B4A, B4J and B4i is responsible for sending the requests and handling the responses.

So apparently it works with B4A, B4J and B4i...

I'm afraid that I cannot further help you.

I explained why jRDC2 was not an ideal solution for me with my project. And I explained why I needed help with PostString and that PostMultipart did not work on my server (I do not know why). Forcing me to use jRCD2 when it is not fully compatible with my needs is not helpful to me. Yes, perhaps you can't or won't help me. But others might. Or they might some day have issues such as mine. I reported facts as I experienced them. I also told you I would look into jRDC2 because you went out of your way to help me by suggesting it strongly. But I only have so much time and energy and with PostString now working in an apparent acceptable manner, I have to move on to other things. I have spent dozens of hours with this and cannot afford more time with another unknown. But thank you for your original suggestion of using POST instead of GET because of the URL encoding that is performed. This was the start to getting on a better path.
 
Upvote 0
Top