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

时间:2015-10-01 10:33:44

标签: android httpclient

我必须使用短划线发布时间戳或其他字符串" - "喜欢" 2015-09-26 13:09:25"

但是在使用服务器中的HttpClient从android发帖后我收到时间戳= 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();
        }

1 个答案:

答案 0 :(得分:0)

最好的方法是以毫秒为单位传递日期,并以服务器端所需的任何格式转换它。

例如

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