1
我嘗試使用俄文字母向網頁發送http文章。unicode post中的編碼不正確
因此,我發送的密碼"руский"
在Chrome Developer Tool中顯示爲"%F0%F3%F1%EA%E8%E9"
,但是當我通過手機發現它時,我收到"%D1%80%D1%83%D1%81%D0%BA%D0%B8%D0%B9"
。
那麼,什麼編碼我需要在我的文章中使用?
詩我不是俄羅斯
這裏是代碼
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
}
}
好使用CP1251爲您的編碼字符集,現在的密碼是正確的,但我還是無法登錄(( – 2014-08-31 17:44:54
使用此編碼發送給服務器的所有數據(您的代碼中的所有URLEnconder ...) – sergiomse 2014-08-31 17:48:34
像這樣? (新的BasicNameValuePair(「action2」,URLEncoder.encode(「post」,「windows-1251」))); nameValuePairs.add(new BasicNameValuePair(「name2」,URLEncoder.encode(login,「windows-1251」))); nameValuePairs.add(new BasicNameValuePair(「password」,URLEncoder.encode(password,「windows-1251」))); nameValuePairs.add(new BasicNameValuePair(「auto_enter」,URLEncoder.encode(「y」,「windows-1251」)));' – 2014-08-31 17:51:59