Issue #24 resolved

Use POST is very slow

keskispas
created an issue

Hi,

I have an issue with GeckoFX 14.

When I post data using GET verb, the program is fast, nothing to say.

But when I try with POST verb, the program stay stucked in "while(webBrowser.isbusy){...}" during 30s, each time !

I really don't know what's wrong with my code or how to do another way.

I tried on my own server, on localhost, on Internet : each time, its too long.

Thanks for your help !

There, is my code :

string xrPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
        xrPath = xrPath.Substring(0, xrPath.LastIndexOf(@"\") + 1) + @"Lib\xulrunner";

        Xpcom.Initialize(xrPath);

        GeckoWebBrowser webBrowser = new GeckoWebBrowser();

        if (!webBrowser.Created) webBrowser.CreateControl();

        while (!webBrowser.IsHandleCreated)
        {
            Application.DoEvents();
        }

        webBrowser.Size = new Size(800, 600);
        webBrowser.Margin = Padding.Empty;
        webBrowser.BringToFront();
        webBrowser.SetBounds(webBrowser.Location.X, webBrowser.Location.Y, 800, 600);

        GeckoMIMEInputStream geckoPostData = new GeckoMIMEInputStream();
        GeckoMIMEInputStream geckoHeaders = new GeckoMIMEInputStream();
        if (!string.IsNullOrEmpty(_postData))
        {                
            Encoding encoding = Encoding.UTF8;
            byte[] postDataArray = encoding.GetBytes(_postData);
            geckoPostData.SetData(_postData);

            geckoHeaders.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            geckoHeaders.AddHeader("Content-Length", postDataArray.Length.ToString());
        }
        else
        {
            geckoPostData = null;
            geckoHeaders = null;
        }

        // Les paramètres sont passés en POST
        webBrowser.Navigate(_url, GeckoLoadFlags.None, "about:blank", geckoPostData, geckoHeaders);

        while (webBrowser.IsBusy)
        {
            Application.DoEvents();
        }

        _bitmap = new Bitmap(webBrowser.Bounds.Width, webBrowser.Bounds.Height);

        _bitmap = webBrowser.GetBitmap((uint)webBrowser.Bounds.Width, (uint)webBrowser.Bounds.Height);

        webBrowser.Dispose();

Comments (7)

  1. keskispas reporter

    Hi,

    Now I use the "DocumentCompleted" event, but the problem is still the same : this event occurs 30 seconds after the "Navigate()" method was called.

    Still investigating...

  2. keskispas reporter

    Hi,

    I succeeded to solve my problem because of an other post on an issue : https://bitbucket.org/geckofx/geckofx-2.0/issue/17/navigate-postdata-headers-dont-work.

    Instead of set the content length with geckoHeaders.AddHeader("Content-Length", length), I set this boolean to true : geckoHeaders.AddContentLength.

    And, as if it is know linked to the solution : - I used the same instance of "GeckoMIMEInputStream" to set posted datas and headers. - I used DocumentCompleted event.

    And all my problem are solved !

    PS : "while(webBrowser.IsBusy){}" is still useful.

  3. keskispas reporter

    My source code :

    GeckoMIMEInputStream geckoPostData = new GeckoMIMEInputStream();
    
    if (!string.IsNullOrEmpty(_postData))
    {                
          Encoding encoding = Encoding.UTF8;
          byte[] postDataArray = encoding.GetBytes(_postData);
          geckoPostData.AddContentLength = true;
          geckoPostData.SetData(_postData);
    
          geckoPostData.AddHeader("Content-Type", "application/x-www-form-urlencoded");
    }
    else
    {
          geckoPostData = null;
    }
    ...
    webBrowser.Navigate(_url, GeckoLoadFlags.None, "about:blank", geckoPostData );
    ...
    
  4. Andrea M

    Hi,I am the same problem when i Navigate the page.jsp.The DocumentCompleted event return after 30 or more seconds!i have try to use your Example source code but the problem persist!have you an idea?

  5. keskispas reporter

    Hi,

    The main points that lead to the solution were :

    1 - Set "geckoPostData.AddContentLength" to true before doing anything on this object

    2 - Do not use "geckoPostData.AddHeader("Content-Length", ...)"

    Can you verify the JSP server is not responsible of the delay ? Or scripts in the page ?

    I think I have had the same problem when "_postData" was empty or malformed.

  6. Andrea M

    thanks for your answer,well: If i used xulrunner15 i have this problem when Navigate jsp page,But if i used xulrunner16, Navigate page jsp is very fast,but in the object gekoWebBrowser the Document is null!..and the domDocument for everithing metods(for example domDocument.GetElementsBytagName("body")) return Exception:

    Impossible Execute cast of object COM di tipo 'System.__ComObject' in type 'Gecko.nsIDOMHTMLElement'.

  7. Log in to comment