0

I have small application in C# 4.0. Remote server is Apache2.

I have problem with error: The remote server returned an error: (414) Request-URI Too Large when I send here data using POST method.

I try use this code to connect to apache2:

        String mainAddressWebApi = "http://myremoteserver.domain.pl/alias/index.php";
        private HttpWebRequest request;
        request = (HttpWebRequest)WebRequest.Create(this.mainAddressWebApi);
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Referer = "http://stackoverflow.com";
        request.UserAgent = "Mozilla/5.0";
        request.CookieContainer = cookie;
        NetworkCredential credentials = new NetworkCredential("login", "password");
        this.request.Credentials = credentials; 

        Byte[] byteData = utf8.GetBytes(data);
        request.ContentLength = byteData.Length;

        Stream newstream = request.GetRequestStream();
        newstream.Write(byteData, 0, byteData.Length);
        newstream.Close();

        this.response = (HttpWebResponse)request.GetResponse();     //I get error here

Data should send using POST. Data have max to 2mb. Can you help me?

Bartosz Kowalczyk
  • 1,479
  • 2
  • 18
  • 34

2 Answers2

0

I had a similar problem once and the solution for me was the first answer here: How to Avoid Server Error 414 for Very Long QueryString Values Maybe it can help you for very long Query Strings?

Community
  • 1
  • 1
Underlines
  • 809
  • 1
  • 8
  • 17
0

Had a similar issue, except that POST was working, but second POST with exactly same parameters returned 414.

Setting request.KeepAlive = false; solved the problem

pinckerman
  • 4,115
  • 6
  • 33
  • 42