开发者

Android: Posting Date object to PHP using HTTPClient

开发者 https://www.devze.com 2023-03-27 12:05 出处:网络
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 appre

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

精彩评论

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

关注公众号