Ejemplo n.º 1
0
        /// <summary>
        /// Send a tcp message
        /// </summary>
        /// <param name="httpViewModel"></param>
        /// <returns></returns>
        /// <remarks>
        /// Test URLs
        /// http://httpbin.org/robots.txt
        /// http://httpbin.org/get
        /// http://httpbin.org/post
        /// </remarks>
        public ActionResult SendTcpMessage(HttpViewModel httpViewModel)
        {
            if (httpViewModel == null)
            {
                throw new ArgumentNullException(nameof(HttpViewModel));
            }

            Uri  uriResult;
            bool result = Uri.TryCreate(httpViewModel.HttpRequest, UriKind.Absolute, out uriResult) &&
                          (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

            if (!result)
            {
                httpViewModel.HttpResponse = "Not a valid URL";

                return(PartialView("_HttpResponse", httpViewModel));
            }

            string response = "";

            if (httpViewModel.HttpRequestType == HttpRequestType.Get)
            {
                response = HTTPManager.SendGetRequest(httpViewModel.HttpRequest);
            }
            if (httpViewModel.HttpRequestType == HttpRequestType.Post)
            {
                response = HTTPManager.SendPostRequest(httpViewModel.HttpRequest);
            }

            httpViewModel.HttpResponse = response;

            return(PartialView("_HttpResponse", httpViewModel));
        }