나는이 작업을 얻으려고하는데 실패했습니다.PostAsJsonAsync 및 익명 형식 - 404 찾을 수 없음 오류
나는 API에 AttributeRouting을 사용하고 있는데 나는이 방법은 내 WebAPI에 정의 : 나는 다음과 같은 코드를 사용하여이 전화를 할 때
[POST("update"), JsonExceptionFilter]
public HttpResponseMessage PostUpdate([FromJson] long id, DateTime oriDt, string notes, int score)
가 :
using (var httpClient = new HttpClient(CreateAuthorizingHandler(AuthorizationState)))
{
var args = new { id, oriDt, notes, score };
var postData = new List<KeyValuePair<string, string>>();
postData.Add(new KeyValuePair<string, string>("id", id.ToString()));
postData.Add(new KeyValuePair<string, string>("oriDt", oriDt.ToString(_dateService.DefaultDateFormatStringWithTime)));
postData.Add(new KeyValuePair<string, string>("notes ", notes));
postData.Add(new KeyValuePair<string, string>("score ", score.ToString(CultureInfo.InvariantCulture)));
var response = httpClient.PostAsJsonAsync(ApiRootUrl + "update", postData).Result;
if (response.IsSuccessStatusCode)
{
var data = response.Content.ReadAsAsync<bool>().Result;
return data;
}
return null;
}
응답은 항상 404 - not found
. 내가 여기서 무엇을 놓치고 있니? 동일한 문제가있는 코드에서 args
이라는 익명 개체를 사용해 보았습니다.
나는 또한 동일한 결과를 가지고 [FromJson]
속성을 사용해 보았습니다.