远程服务器返回错误:(414)Request-URI Too Large

时间:2012-08-06 13:27:32

标签: c# apache

我在C#4.0中有一个小应用程序。远程服务器是Apache2。

我有错误的问题: 远程服务器返回错误:(414)当我使用POST方法向此发送数据时,Request-URI太大。

我尝试使用此代码连接到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

数据应使用POST发送。数据最多为2mb。你能帮助我吗?

2 个答案:

答案 0 :(得分:0)

我曾遇到类似的问题,我的解决方案是第一个答案: How to Avoid Server Error 414 for Very Long QueryString Values 也许它可以帮助你查询很长的查询字符串?

答案 1 :(得分:0)

有一个类似的问题,除了POST正在工作,但第二个具有完全相同参数的POST返回414。

设置request.KeepAlive = false;解决了问题