Getting Operation Timed error if posting request to other ports rather than specified 6007 port in c# .net

40 Views Asked by At
private static string GetWebResponseMsg(string URI, string jsonRequest, string method)
    {
        try
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(URI);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            httpWebRequest.ContentType = "application/json; charset=utf-8";
            httpWebRequest.Method = method;
            if (!string.IsNullOrEmpty(jsonRequest))
            {
                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(jsonRequest);
                    streamWriter.Flush();
                }
            }
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                return streamReader.ReadToEnd();
            }
        }
        catch (WebException ex)
        {
            string _result = string.Empty;
            var httpResponse = (HttpWebResponse)ex.Response;
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                _result = streamReader.ReadToEnd();
            }

            LogAndNotify(method, URI, jsonRequest, ex);
            return _result;
        }
        catch (Exception ex)
        {
            LogAndNotify(method, URI, jsonRequest, ex);
            throw ex;
        }
    }
0

There are 0 best solutions below