jsonhttpresponsedotnetbrowser

dotNetBrowser: HTTP GET Response missing data


I'm using HTTP GET-Response to retrieve large JSON data. Following the document I found here: (https://dotnetbrowser-support.teamdev.com/docs/guides/gs/network.html#network-events-&-handlers), I'm able to receive about 80% data with ResponseBytesReceived in each request. I know my HTTP server is working fine because I can get all the data in the Google Chrome. Using the Microsoft .Net HttpWebRequest/GetResponse APIs, I can also get all the data.

Because my JSON data are relative large, I see the data coming in many batches and the ResponseBytesReceived handler is also called many times. Most times, data are not received in order. This is also big issue.

Any help would be greatly appreciated. Thank you.


Solution

  • You can consider the following approach instead:

    1. Load the URL via LoadUrl() method;
    2. Wait until the page loading is complete;
    3. Extract JSON from the loaded HTML via DotNetBrowser DOM API.

    In this case, there is no need to assemble the parts of the response in a proper order.

    For example:

    Browser.Navigation.LoadUrl("http://httpbin.org/headers").Wait();
    
    //Get JSON string from the loaded page
    string responseJson = Browser.MainFrame.Document.GetElementByTagName("pre")?.InnerText;
    //Parse it to IJsObject
    IJsObject jsonObject = Browser.MainFrame.ParseJsonString<IJsObject>(responseJson);
    // Access object properties
    string headerValue = ((IJsObject)jsonObject.Properties["headers"]).Properties["Accept-Language"].ToString();
    

    In case of any further questions, feel free to contact us at customer-care@teamdev.com.