[英]Error CS1525: Invalid expression term 'string'
I have this code:我有这段代码:
var advertApiModel = _mapper.Map<AdvertModel>(model);
var jsonModel = JsonConvert.SerializeObject(advertApiModel);
var response = await _client.PostAsync(new Uri(
$"{_baseAddress}/create"),
new StringContent(jsonModel, Encoding.UTF8,
"application/json"
)).ConfigureAwait(false);
var createAdvertResponse = await response.Content.ReadAsAsync<CreateAdvertResponse>().ConfigureAwait(false);
var advertResponse = _mapper.Map<AdvertResponse>(createAdvertResponse);
When I run this and trace it, it keeps getting the error Invalid expression term 'string'
at var response and the terminal displays:当我运行并跟踪它时,它不断收到错误
Invalid expression term 'string'
at var response 并且终端显示:
info: System.Net.Http.HttpClient.IAdvertApiClient.ClientHandler[101] Received HTTP response after 246.85940000000002ms - InternalServerError System.Net.Http.HttpClient.IAdvertApiClient.ClientHandler: Information: Received HTTP response after 246.85940000000002ms - InternalServerError
信息:System.Net.Http.HttpClient.IAdvertApiClient.ClientHandler[101] 在 246.85940000000002 毫秒后收到 HTTP 响应 - InternalServerError System.Net.Http.HttpClient.IAdvertApiClient.ClientHandler:信息:在 246.85940000000002 毫秒后收到 HTTP 响应 - InternalServerError
Welcome to StackOverflow Cosmin Mihalache.欢迎来到 StackOverflow Cosmin Mihalache。
I think using your variable jsonModel instead of the new StringContent may help you:我认为使用您的变量 jsonModel 而不是新的 StringContent 可能会帮助您:
var response = await _client.PostAsync(new Uri(
$"{_baseAddress}/create"),
jsonModel
)).ConfigureAwait(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.