Error 500 when trying to give a post from a JSON to the web service C#

Asked

Viewed 529 times

1

I have a WINDOWS FORM C#application, where I communicate with a web service, when I try to send a very big data from my application to the web service I get error 500.

I can do a POST on any other object in JSON, but when it is this that contains very large data it gives way, the interesting fact is that if I try to get, I can recover this data for my application, I just can’t send to the server.

The big data are: a photo converted to Base64 and a binary file that is also converted to Base64.

Follow the code I 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
        }
    }

This method works cool with smaller json’s.

Who there has a notion of how I can solve this my problem?

inserir a descrição da imagem aqui

1 answer

1

The first thing I would do:

<configuration>
  <system.web>
  <httpRuntime maxMessageLength="409600"
    executionTimeoutInSeconds="300"/>
  </system.web>
</configuration>

If you still can’t solve it, there are other options. Here you can better see all the options that the framework there.

  • If I use Finder for example or POSTMAN , with the same JSON I Gero , it accepts , but especially my application when I try to send this object I get exception ,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.