doushuo8677 2011-08-11 02:08
浏览 65
已采纳

Android:使用HTTPClient将Date对象发布到PHP

I am trying to post a Date object Date date = new Date() to a remote PHP script using HTTPClient but it seems like NameValuePair does not accept any other Java objects other than a String? Would appreciate if you can guide me how to post a Date object using HTTPClient

Here's my code

ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
Date date = new Date();
postParameters.add(new BasicNameValuePair("stringObj", "Test")); //No error
postParameters.add(new BasicNameValuePair("dateTime", date));  //Error here

try{

    String response = CustomHttpClient.executeHttpPost("http://remotewebsite/test.php", postParameters);

catch{
// ...
}
  • 写回答

1条回答 默认 最新

  • dousuize3082 2011-08-11 02:12
    关注

    Cast it to string. Make sure date is not empty/null (I didn't see in your code that you used the date object with some of the methods from the Date class)

    For example:

    postParameters.add(new BasicNameValuePair("dateTime", new Long(date.getTime()).toString())); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fastreport怎么判断当前页数
  • ¥15 Kylin-Desktop-V10-GFB-Release-JICAI_02- 2207-Build14-ARM64.iso有没有这个版本的系统啊
  • ¥15 能不能通过蓝牙将传感器数据传送到手机上
  • ¥20 100元python和数据科学实验项目
  • ¥15 根据时间在调用出列表
  • ¥15 R 包chipseeker 安装失败
  • ¥15 Veeam Backup & Replication 9.5 还原问题
  • ¥15 vue-print-nb
  • ¥15 winfrom的datagridview下拉框变成了黑色,渲染不成功
  • ¥20 利用ntfy实现短信推送