Technical Insights: Azure, .NET, Dynamics 365 & EV Charging Architecture

Tag: http

XML http object cross browser

I believe this will be useful for everyone who wants to implement AJAX manually and make it compatible cross browser.



           // cross-browser method to retrieve an XMLHttp object for asynchronous requests & responses
            function GetHTTPRequest()
            {
                var http_request = false;

                if (window.XMLHttpRequest)
                {
                    // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();

                    if (http_request.overrideMimeType)
                    {
                        http_request.overrideMimeType("text/xml");
                    }
                }
                else if (window.ActiveXObject)
                {
                    // IE
                    try
                    {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (e)
                    {
                        try
                        {
                            http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e) {}
                    }
                }

                return http_request;
            }


407 Proxy authentication required

I found this problem when i try to do any of httpweb request behind proxy and i got error of “407 proxy authentication required”. Normally your company has its own proxy server and sometimes you want to call webservice or reading XML from any website or sending xml to payment gateway.

The workaround this is to use proxy properties of your httpwebrequest variable. this is some snippet

         Dim objRequest As HttpWebRequest
         objSendXML = New XmlDocument
         objRequest = WebRequest.Create(strPaymentURL)
         objRequest.Method = "POST"
         objRequest.ContentLength = strSend.Length
         objRequest.ContentType = "text/xml"

        'for development only!!! have to be blocked on production
         objRequest.Proxy = New System.Net.WebProxy("http://proxy-syd:8080", True)
         objRequest.Proxy.Credentials = CredentialCache.DefaultCredentials

Now you can call your webservice or reading xml behind the proxy server

Powered by WordPress & Theme by Anders Norén