나는 내가 쿼리 문자열asp.net web api 2 POST에서 쿼리 문자열을 어떻게 받아 들일 수 있습니까?
http://localhost:53546/api/v1/projects?id=ABA28A61-8898-4739-8464-386C7890E435
로 다음을 게시하려고 컨트롤러를 가지고 있지만 컨트롤러 POST
방법을 공격하지 않습니다
그러나 이것은
http://localhost:53546/api/v1/projects/ABA28A61-8898-4739-8464-386C7890E435
게시물에서 검색어 문자열을 허용하려면 어떻게해야합니까? 504 오류가 계속 발생합니다. 메소드가 지원되지 않습니다. asp.net 웹 API에서 쿼리 문자열을 허용하는 몇 가지 특별한 구문이 있습니까? 여기
내DoPost
방법 여기 내 컨트롤러
[RoutePrefix("api/v1/projects")]
public class ProjectController : ApiController
{
private RestClient client;
public ProjectController() {
client = new RestClient("http://localhost:53546");
}
[HttpPost]
[Route("{id:guid}")]
public string Post(Guid id)
{
return "Here is your Post id - " + id.ToString();
}
}
입니다
public JToken DoRequest(string path, string method, params string[] parameters)
{
if (!path.StartsWith("/"))
{
path = "/" + path;
}
var fullUrl = url + path + ToQueryString(parameters);
if (DebugUrls) Console.WriteLine("Requesting: {0}", fullUrl);
var request = WebRequest.Create(new Uri(fullUrl));
request.Method = method;
request.ContentType = "application/json";
request.ContentLength = 0;
var response = request.GetResponseAsync().Result;
using (var responseStream = response.GetResponseStream())
{
return ReadResponse(responseStream);
}
}
이
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
URL이 경로와 일치하지 않습니다. 왜 그것이 작동하기를 기대합니까? – SLaks
@SLaks 위 쿼리 문자열과 경로를 어떻게 일치시킬 수 있습니까? –
'routeTemplate : "api/{컨트롤러}/{id}",'이미'id '가 경로의 기본 매개 변수라는 것을 이미 정의했기 때문에 ** id = ** 쿼리 문자열 인수가 URL. –