I've developed a method that returns a HTML string by POST. My method works fine but only when the HTML string is small. If the HTML string is large the result will be truncated. For example: If the HTML string has a table with 500 rows, the result is perfect!!! But If the HTML string has a table with 1000 rows, the result only returns 600 rows.
This is the URL: www.aduanet.gob.pe/cl-ad-itconsmanifiesto/manifiestoITS01Alias?accion=cargarFrmConsultaManifiesto&tipo=M
The inputs are 2013 y 788, you can try manually.
I've added the timeout parameter but the problem is the same. I hope that you can help me, please.
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();
}