如何将REST DateTime对象格式化为URI? [英] How do I format a REST DateTime Object to the URI?
问题描述
这是我第一次走上API REST之路。这是我桌面客户端应用程序中的一项功能。似乎日期的格式是错误的原因。任何人都可以看看字符串中是否存在不正常现象。 A部分是第一次尝试,B部分是我现在所处的位置。
谢谢。
This is my first time down the API REST road. This is a function in my desktop client application. It appears that the format of the dates is the cause of the errors. Could anyone please see if there is a malformality in the string. Part A is the first attempt at it, part B is where I am at now.
Thanks.
Public Shared Function SearchCurrentIncidents(ByVal incidentTypeID As Int32, ByVal beginDate As DateTime, ByVal endDate As DateTime) As List(Of IncidentNotificationData)
Try
'A) Response is a 404 Not Found - I suspect too many '/' in the date arguments
Dim uri As String = String.Format(My.MySettings.Default.Local &
"/IncidentNotificationRESTService.svc/SearchCurrentIncidents/{0}/{1}/{2}", incidentTypeID, beginDate, endDate)
uri是:
http:// localhost:60420 /IncidentNotificationRESTService.svc
/ SearchCurrentIncidents / 1/1/14/2013 11:11:55 AM / 1/14/2011 11:11:55 AM
uri is:
http://localhost:60420/IncidentNotificationRESTService.svc
/SearchCurrentIncidents/1/1/14/2013 11:11:55 AM/1/14/2016 11:11:55 AM
'B) Response is a 400 Bad Request
Dim uri As String = String.Format(My.MySettings.Default.Local &
"/IncidentNotificationRESTService.svc/SearchCurrentIncidents/{0}/{1}/{2}",
incidentTypeID,
HttpUtility.UrlEncode(beginDate.ToString("yyyy-MM-ddTHH:mm:ssZ")),
HttpUtility.UrlEncode(endDate.ToString("yyyy-MM-ddTHH:mm:ssZ")))
uri是:
http:// localhost:60420 / IncidentNotificationRESTService.svc / SearchCurrentIncidents / 1 / 2014-0114T13%3a53% 3a44Z / 2016-01-14T13%3a53%3a44Z
uri is:
http://localhost:60420/IncidentNotificationRESTService.svc/SearchCurrentIncidents/1/2014-0114T13%3a53%3a44Z/2016-01-14T13%3a53%3a44Z
Dim request As WebRequest = WebRequest.Create(uri)
throws exception on this call:
response = request.GetResponse()...
推荐答案
执行任何此操作 HTTP / 1.1:协议参数 [ ^ ]帮助你?
(见3.3。例如1)
does any of this HTTP/1.1: Protocol Parameters[^] help you ?
(see 3.3.1 for example)
这篇关于如何将REST DateTime对象格式化为URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!