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.

0

2 Answers 2

1

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

The unencoded : character is allowed in the path component of a URI (tools.ietf.org/html/rfc3986#section-3.3)
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();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.