Android:使用 HTTPClient 将日期对象发布到 PHP
我正在尝试使用 HTTPClient 将 Date 对象 Date date = new Date()
发布到远程 PHP 脚本,但似乎 NameValuePair
不接受除一个字符串
?如果您能指导我如何使用 HTTPClient
发布 Date
对象,我将不胜感激
,这是我的代码
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{
// ...
}
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{
// ...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其转换为字符串。确保
date
不为空/null(我在代码中没有看到您将date
对象与Date
中的某些方法一起使用代码 > 类)例如:
Cast it to string. Make sure
date
is not empty/null (I didn't see in your code that you used thedate
object with some of the methods from theDate
class)For example: