How to Avoid Server Error 414 for Very Long QueryString Values

↘锁芯ラ 提交于 2019-12-09 23:25:58

问题


I had a project that required posting a 2.5 million character QueryString to a web page. The server itself only parsed URI's that were 5,400 characters or less. After trying several different sets of code for WebRequest/WebResponse, WebClient, and Sockets, I finally found the following code that solved my problem:

HttpWebRequest webReq;
HttpWebResponse webResp = null;
string Response = "";
Stream reqStream = null;
webReq = (HttpWebRequest)WebRequest.Create(strURL);

Byte[] bytes = Encoding.UTF8.GetBytes("xml_doc=" + HttpUtility.UrlEncode(strQueryString));
webReq.ContentType = "application/x-www-form-urlencoded";
webReq.Method = "POST";
webReq.ContentLength = bytes.Length;
reqStream = webReq.GetRequestStream();
reqStream.Write(bytes, 0, bytes.Length);
reqStream.Close();
webResp = (HttpWebResponse)webReq.GetResponse();

if (webResp.StatusCode == HttpStatusCode.OK)
{
     StreamReader loResponseStream = new StreamReader(webResp.GetResponseStream(), Encoding.UTF8);
     Response = loResponseStream.ReadToEnd();
}

webResp.Close();
reqStream = null;
webResp = null;
webReq = null;

回答1:


You don't need to use the sockets manually. You can use the HttpWebRequest object to handle the socket layer. You can see the answers on this other question for some sample code that will post a file. Just change the destination URL to an HTTPS url for it to use SSL.



来源:https://stackoverflow.com/questions/2926467/how-to-avoid-server-error-414-for-very-long-querystring-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!