1
Я пытаюсь отправить http сообщение с русскими буквами на веб-страницу.Неправильная кодировка в сообщении unicode
Итак, я отправляю пароль "руский"
, что в Chrome Developer Tool показано как "%F0%F3%F1%EA%E8%E9"
, но когда я его с телефона, я получаю "%D1%80%D1%83%D1%81%D0%BA%D0%B8%D0%B9"
.
Итак, что кодировать мне нужно использовать в моем посте?
Ps Я не русский
Вот код
public void postData(String login, String password, int enter) throws URISyntaxException {
HttpPost httppost = null;
HttpResponse response = null;
Authorization.httpClient = new DefaultHttpClient();
Authorization.cookieStore = new BasicCookieStore();
Cookie cookie = new BasicClientCookie("name", "value");
Authorization.cookieStore.addCookie(cookie);
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, Authorization.cookieStore);
if (enter == 1 || enter == 0)
httppost = new HttpPost("http://www.x-bikers.ru/enter.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
if (enter == 1) {
nameValuePairs.add(new BasicNameValuePair("action2", "post"));
nameValuePairs.add(new BasicNameValuePair("name2", URLEncoder.encode(login, "utf-8")));
Log.v("Login", URLEncoder.encode(login, "utf-8"));
nameValuePairs.add(new BasicNameValuePair("password", URLEncoder.encode(password, "utf-8")));
Log.v("Login", URLEncoder.encode(password, "utf-8"));
nameValuePairs.add(new BasicNameValuePair("auto_enter", "y"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.v("", httppost.toString());
response = (Authorization.httpClient.execute(httppost, localContext));
} else if (enter == 0) {
nameValuePairs.add(new BasicNameValuePair("act", "exit"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = (Authorization.httpClient.execute(httppost, localContext));
}
// Execute HTTP Post Request
HttpEntity entity = response.getEntity();
InputStreamReader content = new InputStreamReader(entity.getContent(), "windows-1251");
BufferedReader reader = new BufferedReader(content);
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
Хорошо, теперь правильный пароль, но я до сих пор cant login (( –
Используйте эту кодировку для всех данных, отправляемых на сервер (все URLEnconder ... в вашем коде). – sergiomse
Как так? 'nameValuePairs.add (новый BasicNameValuePair (« action2 », URLEncoder.encode (« post »,« windows-1251 »))); nameValuePairs.add (новый BasicNameValuePair ("name2", URLEncoder.encode (login, "windows-1251"))); nameValuePairs.add (новый BasicNameValuePair («пароль», URLEncoder.encode (пароль, «windows-1251»))); nameValuePairs.add (новый BasicNameValuePair («auto_enter», URLEncoder.encode («y», «windows-1251»))); ' –