1

我正在尝试从 WCF 服务获取以 android 作为客户端的 DateTime (Joda DateTime) 过滤的对象列表。我正在使用 Json 和 REST 来执行请求。

如何将日期时间值作为参数传递?

就像是:

HttpPost request = new HttpPost( SERVICE_URI + "/GetScheduleEntrysByDate/" + date.toString());

和这个:

[OperationContract]
[WebInvoke(Method = "POST",
    UriTemplate = "GetScheduleEntrysByDate/{date}",
    BodyStyle = WebMessageBodyStyle.WrappedRequest,
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json)]
List<ScheduleEntry> GetScheduleEntrysByDate(DateTime date);
4

1 回答 1

0
// you might wanna specify custom params here for the DefaultHttpClient contructor
DefaultHttpClient httpClient = new DefaultHttpClient();

HttpPost request = new HttpPost( SERVICE_URI + "/GetScheduleEntrysByDate/" + date.toString());

List<NameValuePair> bodyParams = new ArrayList<NameValuePair>();
bodyParams.add(new BasicNameValuePair("date", new Date().getTime());
if (bodyParams.size() > 0) {
    try {
        // Include the request body
        post.setEntity(new UrlEncodedFormEntity(bodyParams));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("Body parameters produced unsupported encoding?", e);
    }
}
// sends the POST with params,  you will need to put this in a try catch
try {
    HttpResponse httpResponse = httpClient.execute(request);
} catch (Exception e){
}
于 2012-11-09T17:27:26.667 回答