2

I have the following ASP.NET WebApi controller:

public class FooController : ApiController 
{
    public string Get(DateTime id)
    {
        ...
    }
}

How does the request need to be formatted? I'm getting 400s (Bad Request). Can someone give me an example of a URL to ApiController's Get() with a DateTime, please?

This will work:

http://localhost:2619/api/Foo/2014-09-14

But this will not:

http://localhost:2619/api/Foo/2014-09-14T18:52:00.000Z

And neither will encoding it:

http://localhost:2619/api/Foo/2014-09-14T18%3A52%3A00.000Z

The DateTime I send needs to be expressed as UTC.

FOO
  • 612
  • 5
  • 16

2 Answers2

1

: has special meaning in URLs (port number). You need to escape it:

http://localhost:2619/api/Foo/2014-09-14T18%3A52%3A00.000Z

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • The unencoded `:` character is allowed in the path component of a URI (http://tools.ietf.org/html/rfc3986#section-3.3) – Ryan M Sep 14 '14 at 20:13
0

2014-09-14T18%3A52%3A00.000Z , 2014-09-14T18:52:00.000Z all are worked

allow invalid characters in web.config (https://stackoverflow.com/a/6026291/286330)

<system.web>
    <httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
    <pages validateRequest="false" />
</system.web>

and test action

public String testdt(DateTime? id)
{
    return id == null ? "Empty" : id.ToString();
}
Community
  • 1
  • 1
JTL
  • 74
  • 1
  • 6