WebAPI에 게시하는 MVC 프로젝트가 있습니다. 악센트 문자 (é)를 사용하면 WebAPI [FromBody]의 객체가 null입니다. 악센트 문자가없는 경우 올바르게 채 웁니다. MVC 개체는 올바른 방법이므로 JSON에서 내 API 개체로의 변환 문제가있는 이유를 알 수 없습니다. JSON은 Newtonsoft.Json.JsonConvert.SerializeObject 버전 6.0.1에 의해 생성됩니다.WebApi FromBody 객체 하나의 필드에 분음 부호가 포함되어 있으면 null입니다.
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _authorizationString);
string json = Newtonsoft.Json.JsonConvert.SerializeObject(model);
var response = await client.PostAsync(_url, new StringContent(json, System.Text.Encoding.Default, "application/json"));
string content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
model = JsonConvert.DeserializeObject<Model>(content);
TempData["Model"] = model;
return RedirectToAction("Confirmation");
}
}
//API
[HttpPost]
public HttpResponseMessage ApiMethod([FromBody] ApiObject obj)
{
//obj is null here, but only when there is an accent in one of the obj string properties.
...
}
난 그냥 한 가지 더 발견했다. Fiddler를 사용하여 API에 성공적으로 게시 할 수 있습니다. 나는이 줄에서 JSON을 복사했다. string json = Newtonsoft.Json.JsonConvert.SerializeObject (model);
그래서 PostAsync에 오류가 있습니까?
컨트롤러 동작 코드를 표시하십시오. –