带HttpURLConnection的android Post UTF-8
我使用下面的代码在android和服务器之间交换数据,但我在发送波斯语字符(UTF-8)方面遇到了麻烦。在服务器端,接收到的数据看起来有点像带HttpURLConnection的android Post UTF-8,android,post,server,persian,Android,Post,Server,Persian,我使用下面的代码在android和服务器之间交换数据,但我在发送波斯语字符(UTF-8)方面遇到了麻烦。在服务器端,接收到的数据看起来有点像 代码: 我认为问题出在服务器端。在插入数据库之前,他们必须解码字符串int utf-8格式。@Nas那么什么是解决方案?在后端php r.net r中使用什么类型的平台?其他这可能有助于您以正确的格式插入波斯语文本form@Nas谢谢,但还没有解决,我认为问题出在android代码而不是服务器上,因为使用旧方法(Apache库)一切正常 HttpURLCo
代码:
我认为问题出在服务器端。在插入数据库之前,他们必须解码字符串int utf-8格式。@Nas那么什么是解决方案?在后端php r.net r中使用什么类型的平台?其他这可能有助于您以正确的格式插入波斯语文本form@Nas谢谢,但还没有解决,我认为问题出在android代码而不是服务器上,因为使用旧方法(Apache库)一切正常
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setConnectTimeout(10000);
if (args != null) {
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestMethod("POST");
String query = args.build().getEncodedQuery();
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
outputStream.close();
}