Search code examples
dotnetbrowser

DotNetBrowser modify post data uwitn OnBeforeURLRequest


Following this example : https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110170-modifying-post-put-patch-upload-data , I have created the following code :

public override void OnBeforeURLRequest(BeforeURLRequestParams parameters)
    {
        bool param1Found = false;
        bool param2Found = false;

        if (parameters != null)
        {
            if ("POST" == parameters.Method)
            {
                if (parameters.PostData != null)
                {
                    if (parameters.PostData.ContentType == PostDataContentType.FORM_URL_ENCODED)
                    {
                        PostData post = parameters.PostData;
                        FormData postData2 = (FormData)parameters.PostData;
                        var mata = postData2.GetPairKeys();
                        foreach (var item in mata)
                        {
                            if (item == "abc")
                            {
                                param1Found = true;
                            }
                            else if (item == "def")
                            {
                                param2Found = true;
                            }
                            var coco = postData2.GetPairValues(item);
                            foreach (var item2 in coco)
                            {
                                Console.WriteLine(item + ":" + item2);
                            }
                        }
                        if (param1Found == true && param2Found == true)
                        {
                            FormData postData = (FormData)parameters.PostData;
                            postData.SetPair("abc", "undefined");
                            parameters.PostData = postData;
                        }
                    }
                }
            }
        }
    }

however , I can not find my value in Chrome Developer Tools under Network tab, and for some reason the original code from the above link crashes the app (cast error). Am I missing something ? Can some one point me on the right direction ? Thanks.


Solution

  • I modified POST request using OnBeforeURLRequest and it worked without any issues. Also, I reproduced the described behavior concerning information in Chrome Developer Tools->Network->Headers. It seems that the information was received before Header's modification, but POST request was modified and sent as it should. You can check this using for example Fiddler. Could you please provide more information about an error with which the application crashes?