Senden utf8-Inhalte mit post-Methode an den server in android mit HttpClient
dies ist mein sample-code, aber ich verwendet, HttpProtocolParams.setContentCharset(params, "utf-8"); im mein code aber wenn ich senden utf-8-Daten, erhalte ich nur "?????" im server-Seite (PHP-code)! was ist das problem?
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf-8");
HttpClient httpclient = new DefaultHttpClient(params);
httpclient.getParams().setParameter("http.protocol.content-charset", "UTF-8");
HttpPost httppost = new HttpPost("URL_TO_SERVER");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("uname", name.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("uemail", email.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("udesc", body.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse hresponse = httpclient.execute(httppost);
String response = new Scanner(hresponse.getEntity().getContent(), "UTF-8").useDelimiter("\\A").next();
hresponse.getEntity().consumeContent();
httpclient.getConnectionManager().shutdown();
Log.d("WX", response.toString());
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
//TODO Auto-generated catch block
} catch (IOException e) {
//TODO Auto-generated catch block
}
Du musst angemeldet sein, um einen Kommentar abzugeben.
Vielleicht sollten Sie UTF-8 verwenden für das Unternehmen:
Ich gearbeitet habe,