【发布时间】:2020-06-04 09:56:14
【问题描述】:
我有一个客户端,它会使用 JSON 向我的网页发送一些字符串数据,但是当我发布它时,由于某种原因它总是返回 null。
我的帖子有什么问题吗?
客户:
public async Task TesteAsync(string numeroserie)
{
try
{
var json = Newtonsoft.Json.JsonConvert.SerializeObject(numeroserie);
var data = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json");
var url = "https://localhost:44336/Home/Receive";
var client = new HttpClient();
var response = await client.PostAsync(url, data);
string result = response.Content.ReadAsStringAsync().Result;
MessageBox.Show(result);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
服务器端:
[System.Web.Http.HttpPost]
public string Receive(string json)
{
return json;
}
我的服务器正在使用 ASP.NET MVC。
Server side using breakpoint when the request is made
Client side using break when sending
更新: 我最后要做的是向我的网络服务器发送一个字符串,然后将其返回给客户端。 我没有使用 json 的经验,所以我不知道我所做的是否正确
【问题讨论】:
-
json正确到达服务器?
-
您似乎从stackoverflow.com/a/39414248/11683 获取了代码。你应该注意到comment below。
-
这到达服务器但返回null
-
@JoelFerreira 是
responsenull 还是json参数 null?
标签: c# json asp.net-mvc