Я хочу отправить строку (
Код: Выделить всё
"OK"Код: Выделить всё
numStr=5Вот метод клиента:
Код: Выделить всё
public async void SendBodyAsync(Action onRespond)
{
try
{
string URL = "http://localhost:60039/api/calculator/AddMore";
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, URL);
request.Headers.Add("numStr", "5");
request.Content = new StringContent("OK", Encoding.UTF8, "text/plain"); //causes error
HttpResponseMessage response = await mHttpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
string result = await response.Content.ReadAsStringAsync();
onRespond(result);
}
catch (HttpRequestException ex)
{
Debug.LogError(ex); //Unity3D console Debug
onRespond(null);
}
}
< /code>
Вот действие сервера: < /p>
[Route("api/[controller]/[action]")]
[ApiController]
public class CalculatorController : ControllerBase
{
public string AddMore([FromHeader]string numStr)
{
//string bodyStr;
//get string from Request.Body and set the value to bodyStr
return (int.Parse(numStr) + 10).ToString();
}
}
system.net.webexception: запрос требует буферизации данных для
succeed.образной Httplistener , он считывает request.content как clientContext транслировать правильно. Я думаю, может быть, проблема заключается в том, что request.content < /code> не равна телу http, и маловероятно, что проблема буферизации, как говорится в сообщении об ошибке. Запрос или ...
Как я могу получить и правильно проанализировать строку в корпусе запроса на стороне сервера?>
Подробнее здесь: https://stackoverflow.com/questions/604 ... re-web-api
Мобильная версия