URLEncoder土耳其字符集(Android,Java)

时间:2018-07-02 08:33:55

标签: java php android mysql mobile

URLEncoder土耳其字符集问题 Java代码;

URL url = new URL(register_url);


HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();


httpURLConnection.setRequestMethod("POST");
//httpURLConnection.setRequestProperty("Accept-Charset", "UTF-8");
//httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + "UTF8");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("user_name", "UTF-8")+"="+URLEncoder.encode(user_name, "UTF-8")+"&"+URLEncoder.encode("password", "UTF-8")+"="+URLEncoder.encode(password, "UTF-8");
//String post_data = "user_name="+user_name+"&password="+password;
Log.d("Kayıt Ol Argümanları", post_data);
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "ISO-8859-1"));
String result="";
String line="";
while ((line = bufferedReader.readLine()) != null){
     result+=line;
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();

PHP代码;

<?php 
require "ayar.php";
$user_name = $_POST["user_name"];
$user_pass = $_POST["password"];
//$user_name = mb_convert_encoding($user_name, "UTF-8");
//$user_pass = mb_convert_encoding($user_pass, "UTF-8");
//$user_name = "üğşçöı";
//$user_pass = "asd";
if (is_null($user_name) & is_null($user_pass)) {
    echo "Boş Kısımlar Var";
}else{
    $mysql_qry = "insert into android (ad, sifre) values ('$user_name', '$user_pass')";
if ($conn -> query($mysql_qry) === TRUE) {
    echo "Insert Success ";
}else{
    echo "Error: " . $mysql_qry . "<br>" . $conn->error;
    }
    $conn->close();
}
 ?>

Android输入;

  

üğşçöı

Android日志打印

  

user_name =%C3%BC%C4%9F%C5%9F%C3%A7%C3%B6%C4%B1

MySQL输出; (utf8_general_ci和latin5_turkish_ci)

  

üÄ?Å?çöı

那是我的问题。

我刚刚在PHP代码中使用PDO解决了问题。

0 个答案:

没有答案