Read page with asynchronous call

Asked

Viewed 63 times

0

I make a call via WebRequest and this page has a Javascript function that the result of it cannot recover (it loads an image). I need to wait to finish loading the page for after the page is fully loaded, and I can load the whole page?

Below the code:

            WebRequest request = webRequest.Create("http://www.receita.fazenda.gov.br/aplicacoes/atcta/cpf/consultapublica.asp");
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Console.WriteLine(response.StatusDescription);
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();
            Console.WriteLine(responseFromServer);
            reader.Close();
            dataStream.Close();
            response.Close();
  • has her code ?

  • Enzo Tiezzi, included the code in the question.

  • that responseFromServer Something’s coming ?

  • if it is an image, you will have to use a byte array for this

  • Yes. Yes, it does. It turns out, at the end of page loading, it calls a javascript function, and this function inserts an image within a given div. But as he calls at the end of the shipment, the request does not bring this image understood? I would need a way that he would only load the page after a few seconds, where I know he would have already run the image loading function, you know?

  • 1

    in the javascript part, how is the code? you really have to take some time while he brings the information, but let’s see how you’re doing, to know the best way to do it

  • that documentation explains very well how your problem can also be solved, http://msdn.microsoft.com/en-us/library/86wf6409(v=vs.110). aspx

  • What I’ve noticed is that you’re not doing it asynchronously yet. Right? And you know what this way of doing can be problematic if there is an error in the middle of the process? As a general rule you never call any close in C#. The code must be mounted to ensure that it is always called by the compiler.

  • No, but if I do it asynchronously, do I get what I need? You know how I do it @bigown ?

  • It seems that the best thing is for you to use Webbrowser, and its events, to render this page and interact with HTML content. They have already placed this captcha to hinder automated access to pages. A setback.

  • Have a look: http://stackoverflow.com/questions/18207730/how-to-make-ordinary-webrequest-async-and-awaitable. I’m not sure I understand what you want with this part of the JS.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.