android HttpClient 从 post 字符串中删除破折号

android HttpClient remove dash from post string

我必须 post 时间戳或其他带有破折号“-”的字符串,例如“2015-09-26 13:09:25”

但是在 post 从 android 使用服务器中的 HttpClient 之后,我收到时间戳=2015 09 26 13:09:25

android 应用

基本上删除了破折号
try {
        HttpClient httpClient = new DefaultHttpClient();
        // replace with your url
        String ts=URLEncoder.encode("2015-09-26 13:09:25", "UTF-8");
        HttpPost httpPost = new HttpPost(strUrl);


        //Post Data
        List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(1);
            nameValuePair.add(new BasicNameValuePair("timeStamp", "2015-09-26 13:09:25"));


        UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePair, HTTP.UTF_8);
        httpPost.setEntity(urlEncodedFormEntity);

        HttpResponse response = httpClient.execute(httpPost);
        if (response.getStatusLine().getStatusCode() == 200)
        {
            HttpEntity entity = response.getEntity();
            String json = EntityUtils.toString(entity);
            System.out.println(json);
        }

        } catch (Exception e) {
            // Log exception
            e.printStackTrace();
        }

最好的方法是以毫秒为单位传递日期,并在服务器端将其转换为您想要的任何格式。

例如

nameValuePair.add(new BasicNameValuePair("timeStamp", String.valueOf(System.currentTimeMillis()));