当我尝试将json发布到webservice时,我收到错误500

时间:2015-12-16 21:41:41

标签: c# json winforms web-services

我正在用c#windows窗体开发一个应用程序,当我尝试发送一个大型json时,我得到了一个例外erro 500.

enter image description here

这是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发送其他对象,但是特别是这个拥有大数据的对象我得到了这个异常。 但是,当我尝试从webservice获取这个相同的对象时,它运行得非常好。

问题是,我可以获得这些大数据,但我无法发送相同的数据。

按照我的控制器代码。

[Route("reconhecimento")]
[HttpPost]
    public bool PostPessoasReconhecimento([FromBody]PessoaReconhecimentoModel[] newpessoaReconhecimento)
    {

    PessoaReconhecimentoModel pessoaReconhecimento = new PessoaReconhecimentoModel();
        return pessoaReconhecimento.postPessoaReconhecimento(newpessoaReconhecimento);
    }

1 个答案:

答案 0 :(得分:0)

Joab我想这个问题可能与你请求的维度有关。

尝试检查您的问题是否可以归类为那些问题的副本: Maximum default POST request size of IIS 7 - how to increase 64kB/65kB limit?