3
다른 사이트에서 내 webapi 코드를 치려고 할 때 다음과 같은 오류가 발생합니다.Gettting 요청 URI와 일치하는 HTTP 리소스를 찾지 못했습니다.
다음은 반환되는 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."
는
http://MyServer/ApiToHit/api/Values?samAccountName=someAccount&success=True&permissionName=MyPermission
내가 좋은 성공 문자열을 얻을.
다음 코드를 입력하면 위의 오류 메시지가 나타납니다.
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();
}
여기 여기 내 경로
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 }
);
}
'RouteConfig'가'TestController'에 대한'MapRoute'을 가지고 있지 않아야합니까? 위에서 보인 것은'HomeController'를위한 것입니다. – Shiva
웹 API의 라우트 구성을 표시하십시오. 그것은 보통'WebApiConfig.cs'에 있습니다. – Nkosi
webApiConfig.cs 값을 추가했습니다 (단지 기본값 일뿐입니다). dev에이 정보가 잘 작동하기 때문에 조금 더 많은 정보를 추가했지만 실제 환경에서는 제대로 작동하지 않습니다. – Lareau