为什么“没有找到与请求URI匹配的HTTP资源"?这里? [英] Why is it that "No HTTP resource was found that matches the request URI" here?
问题描述
我的控制器中有这样的代码:
[Route("api/deliveryitems/InsertIntoPPTData/{stringifiedRecord}")]
...我是通过 Postman 调用它的:
http://localhost:21609/api/deliveryitems/InsertIntoPPTData?stringifiedRecord=serNum77;tx2;siteNum2;bla2.xml;ppt_user2;tx_memo2;file_beg2;file_end2
...但是得到:
<代码>{消息:未找到与请求 URI 匹配的 HTTP 资源'http://localhost:21609/api/deliveryitems/InsertIntoPPTData?stringifiedRecord=serNum77;tx2;siteNum2;bla2.xml;ppt_user2;tx_memo2;file_beg2;file_end2'."MessageDetail:找不到与名为deliveryitems"的控制器匹配的类型.}
其他以相同方式创建和调用的 REST 方法也很好——为什么不是这个?它与其他人唯一不同的是它是一个 HttpPost,而其他人是 HttpGet.这有那么大的不同吗?尝试调用此 REST 方法时,我 正在从 Postman 的下拉列表中选择发布".
更新
是的,它显然与作为 Post 并在 URI 中传递 args 无关,因为我现在使用 HttpGet 方法得到相同的结果:
<代码>{消息:未找到与请求 URI 匹配的 HTTP 资源'http://localhost:21609/api/department/getndeptsfromid?firstId=2&countToFetch=12'."MessageDetail:未在与请求匹配的控制器部门"上找到任何操作."}
我是像这样从邮递员那里打电话的:
http://localhost:21609/api/department/getndeptsfromid?firstId=2&countToFetch=12
...它确实出现在我的控制器中:
[HttpGet][Route("api/department/getndeptsfromid/{firstId}/{countToFetch}")]公共列表<部门>GetNDepartmentsFromID(int FirstId, int CountToFetch){返回 CCRService.GetNDepartmentsFromID(FirstId, CountToFetch);}
更新 2
当我更改这段代码时,我以为我即将解决它:
String.Format("api/department/getndeptsfromid/{0}/{1}", FirstId, CountToFetch)
...至此:
String.Format("api/department/getndeptsfromid?firstId={0}&countToFetch={1}", FirstId, CountToFetch)
...但我仍然收到相同的错误信息...
更新 3
我发现这也不起作用:
http://localhost:21609/api/delivery/invnumbyid?ID=33
...所以有一个明确的模式.我所做的每个包含 args/params 的 REST API 调用都以同样的方式失败;所有其他的 (http://localhost:21609/api/deliveries/Count, http://localhost:21609/api/deliveryitems/count, http://localhost:21609/api/department/getall
) 工作得很好.IOW,如果URI中没有args,则发现该方法.如果有 参数,则没有.
所以显然我在 URI 中传递 args/vals 的方式有问题(在单个 arg 的情况下附加?=",在两个 args 的情况下)"?=&=") 和/或我设置路由的方式有问题.具体来说,这种风格有效:
[Route("api/Deliveries/Count")]
...而这种风格没有:
[Route("api/delivery/invnumbyid/{ID}")]
我会尽快给这个问题加分 - 50 分给这个 Gordiesque 结的解开者,如果今天(在设置赏金之前)回答了 100 分.
更新 4
我更改了路由以包含 arg 的数据类型,以便:
[Route("api/delivery/invnumbyid/{ID}")]
-变成这样:
[Route("api/delivery/invnumbyid/{ID:int}")]"
但还是失败了,咆哮着:
<代码>{消息:未找到与请求 URI 匹配的 HTTP 资源'http://localhost:21609/api/delivery/invnumbyid?ID=45'."MessageDetail:在与请求匹配的控制器‘Delivery’上没有找到任何操作."}
然后,在云雀上",我尝试将其输入 Postman:
http://localhost:21609/api/delivery/invnumbyid/45
...它奏效了!(我一直认为它需要是http://localhost:21609/api/delivery/invnumbyid?ID=45
")
但是在 Postman 中也有类似的尝试:
http://localhost:21609/api/department/getndeptsfromid/2/12/
...继续失败,并显示没有为一个或多个必需参数提供值".即使这是命中:
[HttpGet][Route("api/department/getndeptsfromid/{firstId}/{countToFetch}")]公共列表<部门>GetNDepartmentsFromID(int FirstId, int CountToFetch){返回 HHSService.GetNDepartmentsFromID(FirstId, CountToFetch);}
...并且 GetNDepartmentsFromID() 的参数具有预期的值(2 和 12)
更糟糕/更奇怪的是我得到的结果 "http://localhost:21609/api/deliveryitems/InsertIntoPPTData/serNum77;tx2;siteNum2;bla2.xml;ppt_user2;tx_memo2;file_beg2;file_end2代码>"现在:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><头><title>IIS 8.0 详细错误 - 404.0 - 未找到</title><style type="text/css"><!--body{margin:0;font-size:.7em;font-family:Verdana,Arial,Helvetica,sans-serif;}代码{margin:0;color:#006600;font-size:1.1em;font-weight:bold;}.config_source code{font-size:.8em;color:#000000;}前{margin:0;font-size:1.4em;word-wrap:break-word;}ul,ol{margin:10px 0 10px 5px;}ul.first,ol.first{margin-top:5px;}fieldset{padding:0 15px 10px 15px;word-break:break-all;}.summary-container fieldset{padding-bottom:5px;margin-top:4px;}Legend.no-expand-all{padding:2px 15px 4px 10px;margin:0 0 0 -12px;}图例{color:#333333;;margin:4px 0 8px -12px;_margin-top:0px;字体粗细:粗体;字体大小:1em;}a:link,a:visited{color:#007EFF;font-weight:bold;}一个:悬停{文本装饰:无;}h1{font-size:2.4em;margin:0;color:#FFF;}h2{font-size:1.7em;margin:0;color:#CC0000;}h3{font-size:1.4em;margin:10px 0 0 0;color:#CC0000;}h4{font-size:1.2em;margin:10px 0 5px 0;}#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS",Verdana,sans-serif;颜色:#FFF;背景色:#5C87B2;}#content{margin:0 0 0 2%;position:relative;}.summary-container,.content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;}.content-container p{margin:0 0 10px 0;}#details-left{width:35%;float:left;margin-right:2%;}#details-right{width:63%;float:left;overflow:hidden;}#server_version{width:96%;_height:1px;min-height:1px;margin:0 0 5px 0;padding:11px 2% 8px 2%;color:#FFFFFF;背景颜色:#5A7FA5;边框底部:1px 实心#C1CFDD;边框顶部:1px 实心#4A6C8E;字体粗细:正常;字体大小:1em;颜色:#FFF;文本对齐:右;}#server_version p{margin:5px 0;}表{margin:4px 0 4px 0;width:100%;border:none;}td,th{vertical-align:top;padding:3px 0;text-align:left;font-weight:normal;border:none;}th{width:30%;text-align:right;padding-right:2%;font-weight:bold;}thead th{background-color:#ebebeb;width:25%;}#details-right th{width:20%;}表 tr.alt td,表 tr.alt th{}.highlight-code{color:#CC0000;font-weight:bold;font-style:italic;}.clear{clear:both;}.preferred{padding:0 5px 2px 5px;font-weight:normal;background:#006633;color:#FFF;font-size:.8em;}--></风格>头部><身体><div id="内容"><div class="content-container"><h3>HTTP 错误 404.0 - 未找到</h3><h4>您要查找的资源已被删除、更名或暂时不可用.</h4>
<div class="content-container"><字段集><h4>最可能的原因:</h4><ul><li>指定的目录或文件在 Web 服务器上不存在.</li><li>该 URL 包含印刷错误.</li><li>自定义过滤器或模块,例如 URLScan,会限制对文件的访问.</li></fieldset>
<div class="content-container"><字段集><h4>你可以尝试的事情:</h4><ul><li>在 Web 服务器上创建内容.</li><li>查看浏览器 URL.</li><li>检查失败的请求跟踪日志并查看哪个模块正在调用 SetStatus.有关更多信息,请单击<a href="http://go.microsoft.com/fwlink/?LinkID=66439">这里</a>.</fieldset>
<div class="content-container"><字段集><h4>详细错误信息:</h4><div id="details-left"><table border="0" cellpadding="0" cellspacing="0">
<div id="details-right"><table border="0" cellpadding="0" cellspacing="0">
</fieldset>
<div class="content-container"><字段集><h4>更多信息:</h4>此错误表示该文件或目录在服务器上不存在.创建文件或目录并再次尝试请求.<p><a href="http://go.microsoft.com/fwlink/?LinkID=62293&IIS70Error=404,0,0x80070002,7601">查看更多信息»</a></p></fieldset>