![](/img/trans.png)
[英]I am getting error “No HTTP resource was found that matches the request URI”
[英]Getting No HTTP resource was found that matches the request URI
我試圖從其他網站點擊我的webapi代碼時遇到以下錯誤。
這是返回的json消息。
"Message":"No HTTP resource was found that matches the request URI
'http://localhost:47845/api/Test?samAccountName=aasdf&success=True&permissionName=bla'.","MessageDetail":
"No action was found on the controller 'Test' that matches the request."
我獲得了很好的成功。
當我使用以下代碼點擊它時,我收到上面的錯誤消息。
using (var client = new HttpClient(new HttpClientHandler { UseDefaultCredentials = true }))
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var values = HttpUtility.UrlDecode(string.Format(
CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["PathToParameters"].ToString(),
"someAccount".ToUpper(CultureInfo.InvariantCulture),
true.ToString(),
"MyPermission".ToUpper(CultureInfo.InvariantCulture)));
lblResult.Text = string.Empty;
var newUrl = new Uri(ConfigurationManager.AppSettings["Url"].ToString() + values);
// HTTP GET
var response = await client.GetAsync(newUrl, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
//var response = await client.GetAsync(values, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
this.lblResult.Text = await response.Content.ReadAsStringAsync();
}
這是我的api控制器
public class TestController : ApiController
{
// GET: api/Test
public string Get(string samAccountName, bool success, string permissionName)
{
var returnValue = "Success";
return returnValue;
}
}
這是我的路線
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
好的,我找到了這個問題。
我得到了一些混亂的錯誤消息。
上面的錯誤是固定的,因為調用web.config的參數的編碼問題。 我有&
而不是&
在值> _ <
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.