在网页API GET请求邮箱地址 [英] Email Address in Web API GET request
问题描述
我工作中的ASP.NET Web API实现的REST的API。我们想支持的一种情况是通过电子邮件地址做一些用户信息的 GET
请求。
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.
在理想情况下,客户应该能够做这样的事:
Ideally, clients should be able to do something like this:
GET: /api/v1/users/email/your_email@your_domain.com
当我尝试运行此GET请求,如通过浏览器,然后我得到了 404未找到页。
When I attempt to run this GET request, such as through the browser, then I get the 404 Not Found page.
我在做什么错误是导致IIS无法运行我的路由的Web API路由处理?如果我试着要求 / API / V1 /用户/电子邮件/ your_email
,那么它的路线正确。
What am I doing wrong that is causing IIS to not run the Web API route handler for my route? If I try requesting /api/v1/users/email/your_email
, then it routes correctly.
推荐答案
你可以尝试以下,看看它是否适合你?
Can you try the following and see if it works for you?
GET: /api/v1/users/email?id=your_email%40your_domain.com
这假定您的控制器的Get函数是这样的:获取(字符串ID)
,即它需要一个叫做参数 ID
string类型。如果你想让它举个例子,一个参数叫做EMAILADDRESS,那么你会怎么做:
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
请注意在 @
符号连接codeD为 40%
。这也假定您的控制器被称为 EmailController
。
Note the @
sign is encoded as %40
. This also assumes your controller is called EmailController
.
这篇关于在网页API GET请求邮箱地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!