1
Visual Basic 6 / Re:obtener los datos de un número de RUC desde la pagina de la SUNAT?
« en: Enero 30, 2015, 03:24:59 pm »
Hola este es mi intento, encuentro un error de protocolo favor si alguien me da una pista .
Por lo pronto ya logre convertir la imagen a texto con una OCR en NET llamada tessnet2.dll. Lo estoy mandando directo con datos fijos
private void mt_otro3()
{
try
{
//Creating the Web Request.
HttpWebRequest httpWebRequest = HttpWebRequest.Create("http://www.sunat.gob.pe/cl-ti-itmrconsruc/jcrS00Alias") as HttpWebRequest;
//Specifing the Method
httpWebRequest.Method = "POST";
//Data to Post to the Page, itis key value pairs; separated by "&"
string data = "accion=consPorRuc&nroRuc=20100495989&search1:20100495989&codigo=FGRT&tipdoc=1";
//Setting the content type, it is required, otherwise it will not work.
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
//Getting the request stream and writing the post data
using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()))
{
sw.Write(data);
}
//Getting the Respose and reading the result.
HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream()))
{
MessageBox.Show(sr.ReadToEnd());
}
}
catch (WebException wex)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("ERROR:" + wex.Message + ". STATUS: " + wex.Status.ToString());
if (wex.Status == WebExceptionStatus.ProtocolError)
{
var response = ((HttpWebResponse)wex.Response);
sb.AppendLine(string.Format("Status Code : {0}", response.StatusCode));
sb.AppendLine(string.Format("Status Description : {0}", response.StatusDescription));
try
{
StreamReader reader = new StreamReader(response.GetResponseStream());
sb.AppendLine(reader.ReadToEnd());
}
catch (WebException ex) { throw; }
}
throw new Exception(sb.ToString(), wex);
}
}
Gracias.
Por lo pronto ya logre convertir la imagen a texto con una OCR en NET llamada tessnet2.dll. Lo estoy mandando directo con datos fijos
private void mt_otro3()
{
try
{
//Creating the Web Request.
HttpWebRequest httpWebRequest = HttpWebRequest.Create("http://www.sunat.gob.pe/cl-ti-itmrconsruc/jcrS00Alias") as HttpWebRequest;
//Specifing the Method
httpWebRequest.Method = "POST";
//Data to Post to the Page, itis key value pairs; separated by "&"
string data = "accion=consPorRuc&nroRuc=20100495989&search1:20100495989&codigo=FGRT&tipdoc=1";
//Setting the content type, it is required, otherwise it will not work.
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
//Getting the request stream and writing the post data
using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()))
{
sw.Write(data);
}
//Getting the Respose and reading the result.
HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream()))
{
MessageBox.Show(sr.ReadToEnd());
}
}
catch (WebException wex)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("ERROR:" + wex.Message + ". STATUS: " + wex.Status.ToString());
if (wex.Status == WebExceptionStatus.ProtocolError)
{
var response = ((HttpWebResponse)wex.Response);
sb.AppendLine(string.Format("Status Code : {0}", response.StatusCode));
sb.AppendLine(string.Format("Status Description : {0}", response.StatusDescription));
try
{
StreamReader reader = new StreamReader(response.GetResponseStream());
sb.AppendLine(reader.ReadToEnd());
}
catch (WebException ex) { throw; }
}
throw new Exception(sb.ToString(), wex);
}
}
Gracias.