我开发了一种通过POST返回HTML字符串的方法。 我的方法工作正常,但只有当HTML字符串很小时。如果HTML字符串很大,结果将被截断。 例如: 如果HTML字符串有一个500行的表,结果是完美的! 但是如果HTML字符串有一个包含1000行的表,则结果只返回600行。
这是网址:www.aduanet.gob.pe/cl-ad-itconsmanifiesto/manifiestoITS01Alias?accion=cargarFrmConsultaManifiesto&tipo=M
输入为2013年788,您可以手动尝试。
我添加了超时参数,但问题是一样的。 我希望你能帮助我。
public String mtHTML()
{
string tcuri = "http://www.aduanet.gob.pe/cl-ad-itconsmanifiesto/manifiestoITS01Alias?accion=consultarxNumeroManifiesto";
string tcparameters = "CMc1_Anno=2013&CMc1_Numero=788&CG_cadu=118&TipM=mc&CMc1_Terminal=";
StringBuilder lcsb = new StringBuilder();
HttpWebRequest httpRequest = HttpWebRequest.Create(tcuri) as HttpWebRequest;
httpRequest.Method = "POST";
httpRequest.ReadWriteTimeout = 60000;
httpRequest.Timeout = 60000;
httpRequest.ProtocolVersion = HttpVersion.Version11;
// Parameters(TextView)
string postData = tcparameters;
httpRequest.ContentLength = Encoding.ASCII.GetByteCount(postData);
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.Headers.Add("Accept-Encoding: gzip,deflate,sdch");
httpRequest.Headers.Add("Accept-Language: en-US,en;q=0.8");
httpRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
httpRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36";
httpRequest.Referer = "http://www.aduanet.gob.pe/cl-ad-itconsmanifiesto/manifiestoITS01Alias?accion=cargarFrmConsultaManifiesto&tipo=M";
string tcCookie = "ITCONSMANIFIESTOSESSION=JTpnS9cFJJCvBBYsCV4JFfdc2w9L8JbYdh125SnBmkjwK3WxbD6MrPPPhdF9XRYbLJBW31qn29CcVp7QbSWYBST7wYrh7Zz43Qhh0pzF7JYG1wlJKKQ1qJzLJ3vMWz1Cf6mNNLp8b09TcJBpWHtnsyJp26nyJS7p1tGFW29Wt1Mz4KVHmgTChLVGphlzHx57Yxgf1f6g7w2JdZqhVz4JttJDhnbvDv9yDmsMcRVdwQm1JYrlG0twwLHZvnXMkYz9!517535082!NONE";
httpRequest.Headers.Add("Cookie", tcCookie);
using (Stream requestStream = httpRequest.GetRequestStream())
{
byte[] parametersBuffer = Encoding.ASCII.GetBytes(postData);
requestStream.Write(parametersBuffer, 0, parametersBuffer.Length);
}
string responseText = string.Empty;
try
{
using (WebResponse httpResponse = httpRequest.GetResponse())
{
}
}
catch (WebException wex)
{
if (wex.Status == WebExceptionStatus.ProtocolError)
{
using (var response = ((HttpWebResponse)wex.Response))
{
try
{
//Descomprimimos el resultado
StreamReader reader = new StreamReader(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress));
lcsb.AppendLine(reader.ReadToEnd());
}
catch (WebException ex) { throw; }
}
}
//throw new Exception(sb.ToString(), wex);
}
catch (Exception ex) { throw; }
return lcsb.ToString();
}
答案 0 :(得分:1)
使用此配置:
%windir%\system32\inetsrv\appcmd set config -section:requestFiltering -requestLimits.maxAllowedContentLength:1000000
或者参见
Limit WebClient DownloadFile maximum file size
Is there a limit on the size of a http argument value in a HttpWebRequest?