【发布时间】:2016-03-23 05:10:31
【问题描述】:
我正在开发一个 c# windows 窗体的应用程序,当我尝试发送一个大的 json 时,我得到了一个异常错误 500。
这是 POST 的方法
public void POST(string url, string jsonContent)
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "POST";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(jsonContent);
request.ContentLength = byteArray.Length;
request.ContentType = "application/json";
using(Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
long length = 0;
try
{
using(HttpWebResponse response = (HttpWebResponse) request.GetResponse())
{
length = response.ContentLength;
}
}
catch (WebException ex)
{
// Log exception and throw as for GET example above
}
}
我可以在 JSON 中发送其他对象,但特别是这个具有大量数据的对象,我得到了这个异常。 但是当我尝试从 web 服务获取这个相同的对象时,它工作得很好。
问题是,我可以得到这么大的数据,但我不能发送同样的数据。
按照我的控制器的代码。
[Route("reconhecimento")]
[HttpPost]
public bool PostPessoasReconhecimento([FromBody]PessoaReconhecimentoModel[] newpessoaReconhecimento)
{
PessoaReconhecimentoModel pessoaReconhecimento = new PessoaReconhecimentoModel();
return pessoaReconhecimento.postPessoaReconhecimento(newpessoaReconhecimento);
}
【问题讨论】:
-
你点击过
View detail...吗? Web 服务可能对 POST 数据的大小有限制。例如 PHP 的默认限制为 8Mb。 -
我做到了,我使用 c#,我该如何解决?你知道吗?
-
@Joab 如果您了解 Web 异常的基础对象,您可以获得更多详细信息(您获得的 Web 异常实例)。特别是正如肯尼建议的那样,您可以查看问题是否是收入消息的限制。让我知道是否是这种情况以及您是否使用 selfhost 或 iis 作为服务器(我解释了如何修复错误)
-
我使用iis作为服务器,我认为问题是因为我发送的数据很大
标签: c# json winforms web-services