Jump to content
RodrigoMarqui

WebRequest

Recommended Posts

RodrigoMarqui

Amigos, estou precisando fazer o seguinte:

Acessar um site, preencher um campo, clicar nesse botao e ler o retorno.

O site: http://www2.correios.com.br/sistemas/rastreamento/resultado.cfm

Linha que preciso preencher:

<form id="sroForm" name="sroForm" method="post" action="sistemas/rastreamento/ctrl/ctrlRastreamento.cfm?" onSubmit="return validaCodigoSro();">
<input type="hidden" name="acao" id="acao" value="" />
<fieldset>
<label>Consulte a situa��o de seus objetos nos Correios. Digite seu CPF/CNPJ ou at&eacute; 50 c&oacute;digos de 13 d&iacute;gitos cada, separando-os com ponto e v&iacute;rgula. Ex: AA123456789BR;AA987654321BR;AA100833276BR.<br />
<textarea id="objetos" name="objetos" class="f8col fldSRO f3row" style="text-transform:uppercase;" onBlur="this.value=this.value.toUpperCase()" onKeyDown="if (event.keyCode == 13){validaEnter()}"></textarea>
</label>
<span>*Para consultas por CPF/CNPJ, ser� requisitado efetuar login no idCorreios.</span>
<div class="separator"></div>
<div class="btnform">
<input type="submit" id="btnPesq" name="btnPesq" class="btn1 float-right btnSubmit" value="Buscar"/>
</div>
</fieldset>
</form>

o que consegui fazer:

string UrlCorreios = "http://www2.correios.com.br/sistemas/rastreamento/resultado.cfm";
            string data = "objetos=PU633524761BR"; //replace <value>
            byte[] dataStream = Encoding.UTF8.GetBytes(data);


            string request = "http://www2.correios.com.br/sistemas/rastreamento/resultado.cfm";
            WebRequest webRequest = WebRequest.Create(request);
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.ContentLength = dataStream.Length;
            Stream newStream = webRequest.GetRequestStream();
            // Send the data.
            newStream.Write(dataStream, 0, dataStream.Length);
            newStream.Close();
            WebResponse response = webRequest.GetResponse();



            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            using (Stream dataStream2 = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(dataStream2);
                string responseFromServer = reader.ReadToEnd();
                Console.WriteLine(">>>" + responseFromServer);
                textBox.Text += responseFromServer;
            }
            response.Close();

no caso agora como eu recupero essa informação preencho o campo e faço o submit?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.