Jump to content

Anomalies when passing a string from Java to PHP

- - - - -

  • Please log in to reply
2 replies to this topic

#1
TheMZ

TheMZ

    Newbie

  • Members
  • Pip
  • 2 posts
Hello,

I have written a program to read a certain text file from the hard-drive, parse it, and send it to a remote PHP page.

Here is the file-reader, pushing a parsed line into a stack of Strings S1, from which I later extract a batch of 10 lines, and send them to a remote php file:

After passing the string to the PHP page, the PHP code acquires the relevant data using $_POST["data"], and echos it. I noticed strange anomalies in the echoed strings.
Strange special characters appeared in the place of the normal ones. Strings were cut in the middle.

Part of the original string sent was:

Quote

0%Stoica Alina Alina%Formidon Young%74|

Instead, the server logged:

Quote

0%Stoica Alina Alina%Formidon YoungU|

The strange characters lead me to believe there's an encoding problem, but I can't find an explanation for the cut strings...

Could this be a problem on the PHP side? Is there a solution?

Thank you for your time, and sorry for the trouble! :)

Edited by TheMZ, 27 October 2010 - 05:58 AM.


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
You are sending URL escapes along with your query (%xx), you must URL encode them or send them in a portable base64 format.

From the docs it should be something such as this:
java.net.URLEncoder.encode(yourdata.toString(), "ISO-8859-1");

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
TheMZ

TheMZ

    Newbie

  • Members
  • Pip
  • 2 posts

Nullw0rm said:

You are sending URL escapes along with your query (%xx), you must URL encode them or send them in a portable base64 format.

From the docs it should be something such as this:
java.net.URLEncoder.encode(yourdata.toString(), "ISO-8859-1");

The problem was solved. I indeed encoded the string using Base64 as you suggested, and it works perfectly!
Thank you for your time and help! ;)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users