开发者

Android: Posting Date object to PHP using HTTPClient

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> post开发者_JAVA百科Parameters = 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{
// ...
}


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())); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜