HttpWebRequest is hitting to proxy IP address of destination server after upgrading code from .Net Core 2.0 to 3.1 & deployed in windows server 2012

Viewed 37

I upgraded my API project code from .Net core 2.0 to 3.1 and from this project there is an HttpWebRequest which is calling another server. Before upgrading to .Net core 3.1 its working fine locally and in deployed windows server 2012, but after upgrading its working fine locally but not working on server. Here is the code

public XElement Execute(IJxtsCommand request)
    {
        var isBeginSessionCmd = this.IsBeginSessionCommand(request);
        request.AddRequestCredentials<T>();
        LogHelper.Logger?.Info(request.GetRequestXML());
        var httpRequest = (HttpWebRequest)WebRequest.Create(this.jxtsUrl);
        httpRequest.Method = "POST";
        byte[] byteArray = Encoding.ASCII.GetBytes(request.GetRequestXML());
        httpRequest.ContentType = "application/xml";
        httpRequest.ContentLength = byteArray.Length;
        httpRequest.Credentials = CredentialCache.DefaultCredentials;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        if (isBeginSessionCmd || this.cookie.Count > 0)
        {
            httpRequest.CookieContainer = this.cookie;
        }

        var dataStream = httpRequest.GetRequestStream();
        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();
        var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        if (isBeginSessionCmd)
        {
            this.cookie.Add(httpResponse.Cookies);
        }

        var response = isBeginSessionCmd ?
            new StreamReader(httpResponse.GetResponseStream()).ReadToEnd() :
            new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF7).ReadToEnd()
            .Replace(Convert.ToChar(129), '#');

        string xmlString = CleanInvalidXmlChars(response);
        this.CheckErrorResponse(xmlString, request);
        LogHelper.Logger?.Info(xmlString);
        return XElement.Parse(xmlString);
    }

I did some analysis and these are my findings. I captured all the request from server using whireshark and i found out that HttpWebRequest from Upgraded code is hitting to proxy ip adrress of destination server.

Call from upgraded .net core 3.1 code (not working) enter image description here

Call from earlier .net core 2.0 code (working) enter image description here

Any idea why my server is calling the proxy ip address of destination server from upgraded code?

0 Answers
Related