ToolController.cs
2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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;
}
}
}