ToolController.cs 2.46 KB
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using HHECS.Web.Aop;
using HHECS.WebCommon;
using HHECS.WebCommon.Json;
using Microsoft.Extensions.Logging;
using HHECS.WebCommon.Http;
using HHECS.Model.Entities;
using HHECS.WebCommon.SystemHelp.Obj;
using System.Linq;
using System.Linq.Expressions;
using HHECS.BllModel;
using HHECS.Application.Enums;
using Newtonsoft.Json;

namespace HHECS.Web.Controllers.Tool
{
    public class ToolController : BaseController
    {
        private readonly ILogger<ToolController> _logger;
        public ToolController(ILogger<ToolController> logger)
        {
            _logger = logger;

        }

        //
        // GET: 
        public ActionResult QRCode()
        {
            return View();
        }

        public ActionResult Json()
        {
            return View();
        }

        public ActionResult Postman()
        {
            return View();
        }

        [HttpPost]
        public string PostMan(HttpItem httpItem)
        {
            var response = HttpSend(httpItem);
            return response;
        }

        private string HttpSend(HttpItem httpItem)
        {
            if (string.IsNullOrEmpty(httpItem.URL)) return "{\"error\":\"URL is null\"}";
            var method = httpItem.Method;

            var item = new HttpItem()
            {
                URL = httpItem.URL,
                Method = method,

                Referer = httpItem.Referer
            };
            if (method.ToUpper() == "POST")
            {
                if (string.IsNullOrEmpty(httpItem.Postdata)) return "{\"error\":\"The option is post, and the parameter【Postdata】cannot be empty\"}";
                item.Postdata = httpItem.Postdata;
                item.ContentType = httpItem.ContentType;
            }

            if (!string.IsNullOrEmpty(httpItem.Referer)) item.Referer = httpItem.Referer;

            //设置head信息
            if (!string.IsNullOrEmpty(httpItem.HeaderStr))
            {
                var arr = httpItem.HeaderStr.ToString().Split("&$");
                foreach (var value in arr)
                {
                    var temp = value.Split(":");
                    item.Header.Add(temp[0], temp[1]);
                }
            }

            var http = new HttpHelper();
            var result = http.GetHtml(item);
            return result.Html;
        }
    }
}