有以下Java代码:
public static void register(UserInfo info) throws ClientProtocolException, IOException, JSONException, RegistrationException {
List<NameValuePair> params=new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", info.getName()));
params.add(new BasicNameValuePair("email", info.getEmail()));
params.add(new BasicNameValuePair("pass", info.getPassword()));
params.add(new BasicNameValuePair("genus", String.valueOf(info.getGenus())));
String response=doPostRequest(params, REGISTRATION_URL);
}
private static String doPostRequest(List<NameValuePair> params, String url) throws ClientProtocolException, IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = httpclient.execute(httppost);
return getContentFromInputStream(response.getEntity().getContent());
}
private static String getContentFromInputStream(InputStream is) throws IOException {
String line;
StringBuilder sb=new StringBuilder();
BufferedReader reader=new BufferedReader(new InputStreamReader(is));
while((line=reader.readLine())!=null) {
sb.append(line);
}
reader.close();
return sb.toString();
}
正如您在上面看到的,我发送 POST 请求并获得响应。但是在注册方法中,我使用俄语名称(西里尔字母),并且有“??????? ???” 在我的服务器上。我该如何解决?如何编码俄语文本?