上传当前项目状态

This commit is contained in:
2026-05-23 13:54:15 +08:00
parent 3b871f24b3
commit 0e3250c8b8
32 changed files with 22267 additions and 22099 deletions

View File

@@ -1,46 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Net.Http;
using System.Text.RegularExpressions;
namespace WebApi
{
public enum ResponseCode
{
Fail = 00000,
Success = 00200,
}
public class ApiTools
{
private string msgModel = "{{\"code\":{0},\"message\":\"{1}\",\"result\":{2}}}";
public ApiTools()
{
}
public HttpResponseMessage MsgFormat(ResponseCode code, string explanation, string result)
{
string r = @"^(\-|\+)?\d+(\.\d+)?$";
string json = string.Empty;
if (Regex.IsMatch(result, r) || result.ToLower() == "true" || result.ToLower() == "false" || result == "[]" || result.Contains('{'))
{
json = string.Format(msgModel, (int)code, explanation, result);
}
else
{
if (result.Contains('"'))
{
json = string.Format(msgModel, (int)code, explanation, result);
}
else
{
json = string.Format(msgModel, (int)code, explanation, "\"" + result + "\"");
}
}
return new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") };
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Net.Http;
using System.Text.RegularExpressions;
namespace WebApi
{
public enum ResponseCode
{
Fail = 00000,
Success = 00200,
}
public class ApiTools
{
private string msgModel = "{{\"code\":{0},\"message\":\"{1}\",\"result\":{2}}}";
public ApiTools()
{
}
public HttpResponseMessage MsgFormat(ResponseCode code, string explanation, string result)
{
string r = @"^(\-|\+)?\d+(\.\d+)?$";
string json = string.Empty;
if (Regex.IsMatch(result, r) || result.ToLower() == "true" || result.ToLower() == "false" || result == "[]" || result.Contains('{'))
{
json = string.Format(msgModel, (int)code, explanation, result);
}
else
{
if (result.Contains('"'))
{
json = string.Format(msgModel, (int)code, explanation, result);
}
else
{
json = string.Format(msgModel, (int)code, explanation, "\"" + result + "\"");
}
}
return new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json") };
}
}
}

View File

@@ -1,148 +1,148 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace SlMesDbIterface
{
public partial class MyHttpRequest {
public static string MyPost(string url,string jsonStr)
{
string result = "";
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
req.Proxy = null;
req.KeepAlive = false;
byte[] data = Encoding.UTF8.GetBytes(jsonStr);
req.ContentLength = data.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
reqStream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
Console.WriteLine(result);
}
catch (Exception err)
{
Console.WriteLine("<Error> " + err.Message);
}
return result;
}
public static string MyPost(string url,Dictionary<string,string> paramDict, string jsonStr)
{
string result = "";
try
{
StringBuilder builder = new StringBuilder();
builder.Append(url);
if (paramDict.Count > 0)
{
builder.Append("?");
int i = 0;
foreach (var item in paramDict)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
req.Method = "POST";
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
req.Proxy = null;
req.KeepAlive = false;
byte[] data = Encoding.UTF8.GetBytes(jsonStr);
req.ContentLength = data.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
reqStream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
Console.WriteLine(result);
}
catch (Exception err)
{
Console.WriteLine("<Error> " + err.Message);
}
return result;
}
public static string MyGet(string url, Dictionary<string,string> paramDict)
{
string result = "";
StringBuilder builder = new StringBuilder();
builder.Append(url);
if (paramDict.Count > 0)
{
builder.Append("?");
int i = 0;
foreach (var item in paramDict)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
req.Method = "GET";
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
req.Proxy = null;
req.KeepAlive = false;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream rs = response.GetResponseStream();
StreamReader sr = new StreamReader(rs, Encoding.UTF8);
result = sr.ReadToEnd();
sr.Close();
rs.Close();
return result;
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace SlMesDbIterface
{
public partial class MyHttpRequest {
public static string MyPost(string url,string jsonStr)
{
string result = "";
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
req.Proxy = null;
req.KeepAlive = false;
byte[] data = Encoding.UTF8.GetBytes(jsonStr);
req.ContentLength = data.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
reqStream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
Console.WriteLine(result);
}
catch (Exception err)
{
Console.WriteLine("<Error> " + err.Message);
}
return result;
}
public static string MyPost(string url,Dictionary<string,string> paramDict, string jsonStr)
{
string result = "";
try
{
StringBuilder builder = new StringBuilder();
builder.Append(url);
if (paramDict.Count > 0)
{
builder.Append("?");
int i = 0;
foreach (var item in paramDict)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
req.Method = "POST";
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
req.Proxy = null;
req.KeepAlive = false;
byte[] data = Encoding.UTF8.GetBytes(jsonStr);
req.ContentLength = data.Length;
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
reqStream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
result = reader.ReadToEnd();
}
Console.WriteLine(result);
}
catch (Exception err)
{
Console.WriteLine("<Error> " + err.Message);
}
return result;
}
public static string MyGet(string url, Dictionary<string,string> paramDict)
{
string result = "";
StringBuilder builder = new StringBuilder();
builder.Append(url);
if (paramDict.Count > 0)
{
builder.Append("?");
int i = 0;
foreach (var item in paramDict)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(builder.ToString());
req.Method = "GET";
req.ContentType = "text/html, application/xhtml+xml, application/json, */*";
req.Proxy = null;
req.KeepAlive = false;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
Stream rs = response.GetResponseStream();
StreamReader sr = new StreamReader(rs, Encoding.UTF8);
result = sr.ReadToEnd();
sr.Close();
rs.Close();
return result;
}
}
}

View File

@@ -1,147 +1,147 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Text;
using System.Web.Http;
using System.Web.Http.Cors;
using System.Web.Http.SelfHost;
namespace WebApi
{
/// <summary>
///
/// </summary>
public class InitServer
{
/// <summary>
///
/// </summary>
HttpSelfHostConfiguration config = null;
/// <summary>
///
/// </summary>
HttpSelfHostServer server = null;
/// <summary>
///
/// </summary>
/// <param name="port"></param>
public InitServer(int port)
{
config = new HttpSelfHostConfiguration($"http://localhost:{port}");
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
config.MapHttpAttributeRoutes();
//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
// 自定义路由匹配到action
config.Routes.MapHttpRoute(
name: "API Default",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
}
/// <summary>
///
/// </summary>
/// <param name="port"></param>
public void Close()
{
server.CloseAsync();
}
/// <summary>
///
/// </summary>
public class JsonContentNegotiator : IContentNegotiator
{
/// <summary>
///
/// </summary>
private readonly JsonMediaTypeFormatter _jsonFormatter;
/// <summary>
///
/// </summary>
/// <param name="formatter"></param>
public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
{
_jsonFormatter = formatter;
}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="request"></param>
/// <param name="formatters"></param>
/// <returns></returns>
public ContentNegotiationResult Negotiate(Type type, HttpRequestMessage request, IEnumerable<MediaTypeFormatter> formatters)
{
var result = new ContentNegotiationResult(_jsonFormatter, new MediaTypeHeaderValue("application/json"));
return result;
}
public static string Postring1(string url, string token, Dictionary<string, string> dic)
{
string results = "";
//url = "http://172.16.22.15:8000/" + url;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("Authorization", "Bearer " + token);
StringBuilder builder = new StringBuilder();
int i = 0;
foreach (var item in dic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
req.ContentLength = data.Length;
try
{
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
reqStream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
results = reader.ReadToEnd();
}
return results;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return e.Message;
throw;
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Text;
using System.Web.Http;
using System.Web.Http.Cors;
using System.Web.Http.SelfHost;
namespace WebApi
{
/// <summary>
///
/// </summary>
public class InitServer
{
/// <summary>
///
/// </summary>
HttpSelfHostConfiguration config = null;
/// <summary>
///
/// </summary>
HttpSelfHostServer server = null;
/// <summary>
///
/// </summary>
/// <param name="port"></param>
public InitServer(int port)
{
config = new HttpSelfHostConfiguration($"http://localhost:{port}");
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
config.MapHttpAttributeRoutes();
//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
// 自定义路由匹配到action
config.Routes.MapHttpRoute(
name: "API Default",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
}
/// <summary>
///
/// </summary>
/// <param name="port"></param>
public void Close()
{
server.CloseAsync();
}
/// <summary>
///
/// </summary>
public class JsonContentNegotiator : IContentNegotiator
{
/// <summary>
///
/// </summary>
private readonly JsonMediaTypeFormatter _jsonFormatter;
/// <summary>
///
/// </summary>
/// <param name="formatter"></param>
public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
{
_jsonFormatter = formatter;
}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="request"></param>
/// <param name="formatters"></param>
/// <returns></returns>
public ContentNegotiationResult Negotiate(Type type, HttpRequestMessage request, IEnumerable<MediaTypeFormatter> formatters)
{
var result = new ContentNegotiationResult(_jsonFormatter, new MediaTypeHeaderValue("application/json"));
return result;
}
public static string Postring1(string url, string token, Dictionary<string, string> dic)
{
string results = "";
//url = "http://172.16.22.15:8000/" + url;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("Authorization", "Bearer " + token);
StringBuilder builder = new StringBuilder();
int i = 0;
foreach (var item in dic)
{
if (i > 0)
builder.Append("&");
builder.AppendFormat("{0}={1}", item.Key, item.Value);
i++;
}
byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
req.ContentLength = data.Length;
try
{
using (Stream reqStream = req.GetRequestStream())
{
reqStream.Write(data, 0, data.Length);
reqStream.Close();
}
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream stream = resp.GetResponseStream();
//获取响应内容
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
results = reader.ReadToEnd();
}
return results;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return e.Message;
throw;
}
}
}
}
}