简体   繁体   中英

The remote server returned an error: (414) Request-URI Too Large

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?

我曾经遇到过类似的问题,而对我来说,解决方案是这里的第一个答案: 如何针对非常长的QueryString值避免服务器错误414也许它可以为您提供非常长的查询字符串?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM