Android 后编码字符

Android 后编码字符,android,character-encoding,http-post,Android,Character Encoding,Http Post,我正在向php服务器发送一条带有两个参数的POST消息,一个是Base64中的哈希。Base64使用字符“=”作为填充,以便它可以出现在哈希值中 public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.you

我正在向php服务器发送一条带有两个参数的POST消息,一个是Base64中的哈希。Base64使用字符“=”作为填充,以便它可以出现在哈希值中

public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("id", "WAFFTE="));
        nameValuePairs.add(new BasicNameValuePair("stringdata", "data"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
} 

有什么帮助吗?

显然没有必要从post参数中删除“=”,但建议避免与分隔符混淆。因此,最好是在Base64编码中使用标志URL_SAFE和NO_PADDING

我希望这能帮助其他人解决同样的问题

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs),"UTF-8");