Android Question HttpJob and UTF8

Discussion in 'Android Questions' started by aedwall, Apr 28, 2019.

  1. aedwall

    aedwall Active Member Licensed 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.

    job1.Download2(""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))
  2. Erel

    Erel Administrator Staff Member Licensed User

    This is not related to UTF8 encoding.

    The parameters in the array are url encoded. Non-ascii characters (as well as some ascii characters) need to be url encoded. You need to url decode them in your PHP script.

    Other options:
    1. Send the data with a POST request.
    2. Use jRDC2 instead of the PHP script.
  3. aedwall

    aedwall Active Member Licensed User

    >> 1. Send the data with a POST request.

    Should I use something like this?

    job1.PostString(""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:

    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
    "", xxx)


    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?

    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: Apr 28, 2019
    Shelby likes this.
  4. KMatle

    KMatle Expert Licensed 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.
  5. aedwall

    aedwall Active Member Licensed User

    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:

    $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.
  6. DonManfred

    DonManfred Expert Licensed User

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

    I suggest to use
    Dim job As HttpJob
    "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)
    End If
    Last edited: Apr 29, 2019
    ronell likes this.
  7. aedwall

    aedwall Active Member Licensed User

  8. ronell

    ronell Well-Known Member Licensed User

    did you try to decode the data in your php script?
    $city $_POST['city'];

    $city urldecode($city);

  9. DonManfred

    DonManfred Expert Licensed User

    1. Not needed when using postmultipart.
    2. He was using str_replace to replace them by himself. This is a mistake.
  10. aedwall

    aedwall Active Member Licensed User

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

    aedwall Active Member Licensed User

    This is not working for me.

    job1.PostMultipart("", 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:

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


    At least I don't get a 501 error with PostString.
    Last edited: Apr 29, 2019
  12. Erel

    Erel Administrator Staff Member Licensed User

    Why aren't you switching to jRDC2? It is simpler and more powerful.
  13. aedwall

    aedwall Active Member Licensed 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). 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.
  14. Erel

    Erel Administrator Staff Member Licensed User

    Let me try it.
    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.
    DonManfred and LucaMs like this.
  15. aedwall

    aedwall Active Member Licensed User

    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.
  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