Hebrew strings submitted to web server aren't received in Hebrew

余生长醉 提交于 2019-12-10 20:18:54

问题


I submit a sign up form from my app to the web server:

EditText email = (EditText)findViewById(R.id.email);
EditText password = (EditText)findViewById(R.id.password);
EditText nickname = (EditText)findViewById(R.id.nickname);

List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("email", email.getText().toString()));
params.add(new BasicNameValuePair("password", password.getText().toString()));
params.add(new BasicNameValuePair("nickname", nickname.getText().toString()));

HttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost(url);
request.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = httpClient.execute(request);

When I type the nickname in Hebrew, it is received in the server (php/apache) as a string in the same length as the nickname, but with characters which are "invisible", i.e. look like blank spaces. definitely not Hebrew. Any clue someone?


回答1:


I think that just doing request.setEntity(new UrlEncodedFormEntity(params)); encodes your parameters in the DEFAULT_CONTENT_CHARSET (see http://developer.android.com/reference/org/apache/http/client/entity/UrlEncodedFormEntity.html).

You should probably use the UrlEncodedFormEntity(List<? extends NameValuePair> parameters, String encoding) form. Froyo/Android 2.2 added support for displaying text in Hebrew and Arabic (among other languages), including the needed fonts, but I am still looking for Hebrew encoding string...

Have you tried encoding as "UTF-8" or "UTF-16"?



来源:https://stackoverflow.com/questions/7407566/hebrew-strings-submitted-to-web-server-arent-received-in-hebrew

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!