以下是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请求并获取到响应。但是,在注册方法中,我使用了俄语名称(西里尔字母),服务器上出现了“????? ???”。我该如何解决这个问题?如何对俄文进行编码?