尝试使用链接中的代码时收到错误消息。
HttpClient httpClient = new HttpClient();
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url))
{
var body = new RequestModel
{
NewDisplayname = desireddisplayname
};
request.Content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
HttpResponseMessage responseMsg = await httpClient.SendAsync(request).ConfigureAwait(false);
if (responseMsg == null)
{
throw new InvalidOperationException(
string.Format(
"The response message was null when executing operation {0}.",
request.Method));
}
else
{
if (responseMsg.StatusCode == HttpStatusCode.OK)
{
// Get request body
RequestModel data = await req.Content.ReadAsAsync<RequestModel>();
string name = data.NewDisplayname;
}
}
}
错误CS0246:找不到类型或名称空间名称'RequestModel'(您是否缺少using指令或程序集引用?)
错误CS0103:名称'req'在当前上下文中不存在
如何在代码中使用“ RequestModel”?