Email Address in Web API GET request

前端 未结 2 1692
忘了有多久
忘了有多久 2021-01-16 06:46

I\'m working on a REST APIs implemented in ASP.NET Web API. One scenario we\'d like to support is to do a GET request of some user information by email address.

相关标签:
2条回答
  • 2021-01-16 06:58

    Can you try the following and see if it works for you?

    GET: /api/v1/users/email?id=your_email%40your_domain.com
    

    This assumes your controller's Get function is something like this: Get(string id), i.e. it takes a parameter called id of type string. If you want it to take, for example, a parameter called "emailAddress", then you would do:

    GET: /api/v1/users/email?emailAddress=your_email%40your_domain.com
    

    Note the @ sign is encoded as %40. This also assumes your controller is called EmailController.

    0 讨论(0)
  • 2021-01-16 07:15

    I just managed to test it for you.

    The main issue is that "IIS Web Core" confused "." from email address with "." from file extension (e.g. .aspx .php and etc)

    If you remove "." from email address and replace it with "-" or something then it will work.

    Eg.

    GET /api/values/me@gmail-com

     public string Get(string id)
            {
                return "value";
            }
    

    Hope it helps.

    You may see how to remove the default IIS module but I would recommend to reconsider your API design again.

    0 讨论(0)
提交回复
热议问题