我需要你再次帮助这个。我想从Android应用程序发送特殊字符到PHP脚本,反之亦然。Android和PHP之间的特殊字符
的Android代码
...
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.mypage.com/script.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("value", "Español"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){
InputStream inps = response.getEntity().getContent();
InputStreamReader inp = new InputStreamReader(inps, Charset.forName("ISO-8859-2"));
BufferedReader rd = new BufferedReader(inp);
StringBuilder stringBuilder = new StringBuilder();
String bufferedStrChunk = null;
while ((bufferedStrChunk = rd.readLine()) != null) {
stringBuilder.append(bufferedStrChunk);
}
Result = stringBuilder.toString();
}...
PHP代码
<?php
header("Content-Type: text/plain;charset=ISO-8859-2");
echo $_POST["value"];
?>
第一招
我想从Android发送字符串“Español”到PHP。我将该字符串存储到一个MySQL表(UNICODE字符集)中,并正确地获取了字符串。我也得到每个字符的整数值。结果是“Español”和“69.115.112.97.241.111.108”。所以,Android发送字符“ñ”为241,在UNICODE Chart中定义为“ñ”。看到它的http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0080
第二招
我从PHP返回字符串到Android和,而不是让“N”我得到的“N”。这是我迷失的地方。这种变化是什么时候,为什么有相同的数值,他们是不同的?这对我来说太过分了,我请求你的帮助。提前致谢!
为什么你不使用UTF-8? – Rufinus 2012-04-05 13:11:57
在发送任何东西之前使用'base64'。我做了什么以及它的工作 – Baba 2012-04-05 13:13:22