I'm trying to get a list of objects filtering by DateTime (Joda DateTime) with android as client, from a WCF Service. I'm using Json and REST to do the request.
How can I pass the datetime value as a parameter?
Something like:
HttpPost request = new HttpPost( SERVICE_URI + "/GetScheduleEntrysByDate/" + date.toString());
And this:
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "GetScheduleEntrysByDate/{date}",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
List<ScheduleEntry> GetScheduleEntrysByDate(DateTime date);
// 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){
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.