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?
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"?
精彩评论