1 Star 0 Fork 2

fysz007/httpRequestTool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
MainForm.cs 24.99 KB
一键复制 编辑 原始数据 按行查看 历史
fysz007 提交于 2024-11-01 16:13 . pdf打印 SHA265加密
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
using HttpRequest.Helper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Data.SQLite;
using System.IO;
using System.Xml;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Xml.Linq;
using System.Text;
using System.Net;
using System.Security.Policy;
using Microsoft.VisualBasic.Logging;
using System.Reflection.Metadata;
using Spire.Pdf;
namespace HttpRequest
{
public partial class MainForm : Form
{
#region 构造函数
public MainForm()
{
InitializeComponent();
}
#endregion
#region 私有方法
/// <summary>
/// POST请求
/// </summary>
private void requestPost()
{
try
{
Dictionary<string, string> data = new Dictionary<string, string>();
if (txtHeadKey.Text.Trim().Length > 0 && txtHeadValue.Text.Trim().Length > 0)
{
data.Add(txtHeadKey.Text.Trim(), txtHeadValue.Text.Trim());
}
EncryptHelper encryptHelper = new EncryptHelper();
var postData = chkAES.Checked ? encryptHelper.Encrypt(txtRequest.Text.Trim()) : txtRequest.Text;
var response = HttpHelper.HttpPost(txtApiUrl.Text, postData, cbxContentType.Text, 30, data);
txtResponse.Text = chkAES.Checked ? encryptHelper.Decrypt(response) : response;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// Get请求
/// </summary>
private void requestGet()
{
try
{
Dictionary<string, string> data = new Dictionary<string, string>();
if (txtHeadKey.Text.Trim().Length > 0 && txtHeadValue.Text.Trim().Length > 0)
{
data.Add(txtHeadKey.Text.Trim(), txtHeadValue.Text.Trim());
}
#region 模拟
var tag = "piaodetail";//login piaolist piaodetail
switch (tag)
{
case "login":
txtApiUrl.Text = "https://xmj.tking.cn/sellerapi/seller/login?src=web";
var formDatas = new List<FormItemModel>();
//添加文件
formDatas.Add(new FormItemModel()
{
Key = "cellphone",
Value = "18855555886",
});
//添加文件
formDatas.Add(new FormItemModel()
{
Key = "password",
Value = "nGeiWSUjcf0OoAsV6mDDUQ==",
});
//提交表单
var result = PostForm(txtApiUrl.Text, formDatas, null, null, null, 20000, null);
txtResponse.Text = result;
break;
case "piaolist":
#region piao list
txtApiUrl.Text = "https://xmj.tking.cn/sellerapi/seller/undefined/shows?page=1&offset=0&length=20&siteOID=&type=&status=2&supportSeatPicking=&key_words=&sorting=weight&hideSaled=false&seq=DESC";
data.Add("access-token", "eyJ0eXAiOiJKV1QiLCJjdHkiOiJKV1QiLCJ6aXAiOiJERUYiLCJhbGciOiJSUzUxMiJ9.eNpcTz1OwzAUvsubPdjQpLE3hg5IFQOFA7w4rrBw7MhOIlDVCyCkzggYGJBYKvUGnCaUY_Ci0gHe-P2_FUSD7gJrAwqG7dP-8_HrdQcMsMcW43V0oHznHIM6lNaNKlEU2XhFkY-6qrKtDR7duV8GUCtIxjkTFy22XSL5WY_WYUlWBt7q22PXbvO9eRmet_v3j-HhjUhNvuYm-P8dawa2IiyfSGlOy6XQQmPJORe5lFxPyZpCF7U5Lu2SiVf3zZizmM3ns0s4YL_Nf_ebuwaUmJ5kMssFnzDoTUz0D6iMyJq2H2LXPwAAAP__.DoHrG91MgFA61DRbJC76LaoY62kvqXYNtbS9Fa6u1vpFb3Nkqn9gKrSYjwhR-J1O16-jWOf26IyPdcoBAKUEamxDtoP9bW9o-iHnIIkvN1CqdrVZfLrn_b_0nBqZfMMa7Q5LOCBUtsR6gUAJ7iNT08wa_YTx67q56XA1io9fPUE");
//data.Add("cookie", "acw_tc=1a0c595a17258439840071871e003a9dbfba7e8fceb62f301cfb59b6b515ba; JSESSIONID=D300A6ADF0819BB97AF6C9B6EE173F5C; ssxmod_itna=Qq+x0DyDcDRDBQWKGHD8YT4+ECaEeG=qhTGODlrAQxA5D8D6DQeGTT2atWQKCKtiGbRGQDREv3GKWP3mrWKoDpoXoDU4i8DCkDqdTDeW=D5xGoDPxDeDADYE6DAqiOD7qDdfhTXtkDbxi3fxDbDim8mxGCDeKD0ZbFDQKDuE9YKnIxDGvx18G4b2GGPIa+uPOCqWYxeAKD9=oDsEij79Ajn8izPf3LD+4ODlF0DCF1uEyFr4Gd66v1DtxqaGRnT0wqIAbxt7WPKibP52DxqBTg+kWeYDzYNmxl77DDi1DKj3=q4D; ssxmod_itna2=Qq+x0DyDcDRDBQWKGHD8YT4+ECaEeG=qhTGD61RiBGD052xitDLiFN7nOBRWrVdeQ59AgDF6s5O0GKxvlBiLE0CnQiTIdL7sPgf26hCbuk6I8V+ZYEEh5nCZ9xGHfDldKYDLpoz7MxidNEPxyP7TXi0NxzHh7c7O0Dg78PAqhinGtCHPaWGdxbyGho3=YF8TmziAwbaAf9eLxRY14rMERRqfI/4Em8gTmzefRxgT3Yn2h6ldiIAdibyrbdguOcTU7dQhk1STaZ=WzypyDMRhiu7yQ46Eqt9K3qKxh8ATUTi=2mSTeQ=j9qxKq2j4dbcNK7fmapGpj/r09yTY9xNiE/HF09G84rUPVUq2Y4eqa=UwXeEmUmkjn7iTA/hC4Wddc7DYUB7LCq28+drpMATyUo=UcNSg1z+XmcB3F3gOToutcojCTbhfZj3fIBa2oEBfbdAWO8WcfE+gHwKFwuWfGqtxDKMD1DKYaxNho5px42+YYe7ho72imA4upK3ixvhs/70Mpx/PTqpXezqtzQVkDTRY5CD6rxYDxP8+8U=zDuY7DvhT9YXcMwRAphAIwDuai3qG9OoeY72Nh9n29S+xD7=DYKNYGz+9DOMCMkRLGQ7pxlh4IMqG25bzYm2GpzPQUqfvttliQULwKIAUKn+xtzh/CRw2i4X/7DgPD===; tfstk=fz6iT3tdV1R_JqhHxWJ_Mbrs-ZFp5c9X6ZHvkKL4Te8IkCCA0nzcWwQ9gPsA-obFPGdAniMD0i7bfEE_9Gs6hKz8yzeRfG9mTWHVIERELMtj3ny_skvBhKz8JyT14Wvfy7ObCojUxnKm7c72gMrHm3JqQIkZT28B8EJ2uKue8hKrgx-23kjeRhv2ubMr3UXVd9zZKT0CnNofdhAMoxKZnQBKeBTrJeMxHFxMsfIw-xkVK6M5JNYaNDLXBFsBjZwSCdRcgOpFQyy2U__hnQJuMl9lx6CJs64ZneB9RQ6wEmyNxdYMa9Armx_Pxi5Jt9EzFdvw7sp1D04OxObOf9jx0XJMB6AlILyS7ECdqtxchrwhriS5gBXmSgPoTbWVsxtUD9ljGC-BxUeOdLaQd7Cy9kqnN5OwAhU8xkcjGC-BxUE3xbgX_HtTy");
//data.Add("device-id", "a4851a6769385e7a94af0153f7c4d04b");
data.Add("uuid", "66dfe3e8ed2f6f0001b0296c");
data.Add("tsessionid", "66dfe3e8ed2f6f0001b0296b");
var pioaListResponse = HttpHelper.HttpGet(txtApiUrl.Text, cbxContentType.Text.Trim(), data);
txtResponse.Text = pioaListResponse;
#endregion
break;
case "piaodetail":
txtApiUrl.Text = "https://xmj.tking.cn/sellerapi/v1/seller/show/ticket/init";
var formDetail = new List<FormItemModel>();
//添加文件
formDetail.Add(new FormItemModel()
{
Key = "showId",
Value = "65bcc3c87c5b6f00013af6a3",
});
//添加文件
formDetail.Add(new FormItemModel()
{
Key = "optimizeTicketType",
Value = "WEIGHT",
});
Dictionary<string, string> headersDetail = new Dictionary<string, string>();
headersDetail.Add("access-token", "eyJ0eXAiOiJKV1QiLCJjdHkiOiJKV1QiLCJ6aXAiOiJERUYiLCJhbGciOiJSUzUxMiJ9.eNpcTz1OwzAUvsubPcSFJLY3hg5IFUNLD_DiuMLCsSM7iYqqXqCq1BkBAwMSS6XegNOEcgwctR3gjd__W4FXaO6wUiCg3z8fv7bfbwcggB026OfegLCtMQQqV2gzqChj6XCMZYOuLHWjnUVzaxcOxAqCMkb5WYNNG6L8pkNtsIhWAlbLx0vXYfeze-1f9sePz37zHkkZffWDs_871gR0GbHsmnN1VSyopBKLJEloxnki82gNrvVSXZa2Qfn7p3rImY0nk_EUTti5-e9-taxB0HyU8jTLKSPQKR_iPyDSSFZx-yl2_QsAAP__.EwjsotY4C6fW3vUsSKyvgQ6lf8oOyal3YEJz_2iyet0xQ15Pd3liebFCrW6qW3yNTbrQASORCKFCTTwhT6sKvJRMZ86vNp9hHXYaIk_u6GG3FMvHLmY-x8sO20UslNcyItY1yOJB0wlmDjtDJnUcMUwOpafhdtZtyovyq0BmvJk");
headersDetail.Add("uuid", "66dfe64eed2f6f0001b0390c");
headersDetail.Add("tsessionid", "66dfe64eed2f6f0001b0390b");
//headersDetail.Add("device-id","8c670cd2431d55eaa25cb3c7efa5f657");
//headersDetail.Add("src", "web");
//headersDetail.Add("cookie", "acw_tc=0aef342417259495025713655e00cb52f3449d6b000bb4ff56e199e75ab3eb; auth_token=eyJ0eXAiOiJKV1QiLCJjdHkiOiJKV1QiLCJ6aXAiOiJERUYiLCJhbGciOiJSUzUxMiJ9.eNpcTz1OwzAUvsubPcSFJLY3hg5IFUNLD_DiuMLCsSM7iYqqXqCq1BkBAwMSS6XegNOEcgwctR3gjd__W4FXaO6wUiCg3z8fv7bfbwcggB026OfegLCtMQQqV2gzqChj6XCMZYOuLHWjnUVzaxcOxAqCMkb5WYNNG6L8pkNtsIhWAlbLx0vXYfeze-1f9sePz37zHkkZffWDs_871gR0GbHsmnN1VSyopBKLJEloxnki82gNrvVSXZa2Qfn7p3rImY0nk_EUTti5-e9-taxB0HyU8jTLKSPQKR_iPyDSSFZx-yl2_QsAAP__.EwjsotY4C6fW3vUsSKyvgQ6lf8oOyal3YEJz_2iyet0xQ15Pd3liebFCrW6qW3yNTbrQASORCKFCTTwhT6sKvJRMZ86vNp9hHXYaIk_u6GG3FMvHLmY-x8sO20UslNcyItY1yOJB0wlmDjtDJnUcMUwOpafhdtZtyovyq0BmvJk; tsessionid=66dfe64eed2f6f0001b0390b; uuid=66dfe64eed2f6f0001b0390c; nickName=%E5%B0%8F%E8%8F%9C%E5%9B%AD%E7%A5%A8%E5%8A%A1; sellerOID=6499e3bf1c1cab00016990c7; SESSION=ZTRiMzE3MDQtNmJkNS00NzNmLWE1OGUtMjc2MTkzMTg2MzJj; ssxmod_itna=Yqr=YIqAOGkKGHfqll3GCWB47IbxDthiPaDl174A5D8D6DQeGTiX3hD0D=mNWmdWwTDMYO2Ei7D7uEo3bRlWUEaGDB3DEx06trWDxiiuDCeDIDWeDiDG4Gm94GtDpxG=DjAKtZSjxYPDEAKDYxDrfrKDRxi7DDHdOx07DQv8dcrt6pqDBpwvgm2xqY7hOpBCrKH5PIG8D7ymDlax2IOwRbktgaBfoDBomx0kxq0Oc=vzkPoDUn9z9xYNi=D7MQDoW6ux7Q0x7915Gc2Yd6n47nDKFxKPgDiTM0UDD===; ssxmod_itna2=Yqr=YIqAOGkKGHfqll3GCWB47IbxDthiPDnxnKDQDlO4Q90HY9DL30351qBPfh0oTW=F5n2u5im9RaAyXGeteRANAdTnD08DeTpD; JSESSIONID=D2E021380E607224F03A0DE90872FFA8; tfstk=fN5Z2o6-i5FN_rNufFR284nFNoA9ZCq7mstXoZbD5hxiGNwVLaIO5K11onW2xg4O5iM1YIb5vja9cOsV39jUWKwO1j5VVMGXjEYM3nSDk1imslhH3USWmnfVkj8coiU9cPeCWNdviuZ7V7_OWw-2uOzWSp4DPE0MFqH_ENdvik1BXQ2FWgkdAnCMiyRHlFYMidvMty82PIcMnfDnxHKHmIvmIXVHrE0iiIA08wxpoIxmiTfcwxL6IzrbPhXxvcvJqNxG-wfHW0tcSHlmlh8wQV_MYjccT9hRAG-ge2tv1hQp7iF-6CvVn1OhskVDZTIFgLAzhPdP896WQ9rigH16vLCMaqVG8C-wE6JoujIl8ZXWL6auwCRMjtOOl4r181S1W67jovAw19JP_QV-jn6Czs8VMoFF4ZbRnp5qbgyoDejPisCYMxJMJe-78ylM1Ku3fWHoxxHvByLeVyxjHxpMJe-78ykxHdUp83aHc");
//提交表单
var resultDetail = PostForm(txtApiUrl.Text, formDetail, null, null, null, 20000, headersDetail);
txtResponse.Text = resultDetail;
break;
}
if (tag != "") return;
#endregion
EncryptHelper encryptHelper = new EncryptHelper();
var response = HttpHelper.HttpGet(txtApiUrl.Text, cbxContentType.Text.Trim(), data);
txtResponse.Text = chkAES.Checked ? encryptHelper.Decrypt(response) : response;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 使用Post方法获取字符串结果
/// </summary>
/// <param name="url"></param>
/// <param name="formItems">Post表单内容</param>
/// <param name="cookieContainer"></param>
/// <param name="timeOut">默认20秒</param>
/// <param name="encoding">响应内容的编码类型(默认utf-8)</param>
/// <returns></returns>
public static string PostForm(string url, List<FormItemModel> formItems, CookieContainer cookieContainer = null, string refererUrl = null, Encoding encoding = null, int timeOut = 20000, Dictionary<string, string> headers = null)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
#region 初始化请求对象
request.Method = "POST";
request.Timeout = timeOut;
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
request.KeepAlive = true;
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36";
if (headers != null)
{
foreach (var header in headers)
request.Headers.Add(header.Key, header.Value);
}
if (!string.IsNullOrEmpty(refererUrl))
request.Referer = refererUrl;
if (cookieContainer != null)
request.CookieContainer = cookieContainer;
#endregion
string boundary = "----" + DateTime.Now.Ticks.ToString("x");//分隔符
request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
//请求流
var postStream = new MemoryStream();
#region 处理Form表单请求内容
//是否用Form上传文件
var formUploadFile = formItems != null && formItems.Count > 0;
if (formUploadFile)
{
//文件数据模板
string fileFormdataTemplate =
"\r\n--" + boundary +
"\r\nContent-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"" +
"\r\nContent-Type: application/octet-stream" +
"\r\n\r\n";
//文本数据模板
string dataFormdataTemplate =
"\r\n--" + boundary +
"\r\nContent-Disposition: form-data; name=\"{0}\"" +
"\r\n\r\n{1}";
foreach (var item in formItems)
{
string formdata = null;
if (item.IsFile)
{
//上传文件
formdata = string.Format(
fileFormdataTemplate,
item.Key, //表单键
item.FileName);
}
else
{
//上传文本
formdata = string.Format(
dataFormdataTemplate,
item.Key,
item.Value);
}
//统一处理
byte[] formdataBytes = null;
//第一行不需要换行
if (postStream.Length == 0)
formdataBytes = Encoding.UTF8.GetBytes(formdata.Substring(2, formdata.Length - 2));
else
formdataBytes = Encoding.UTF8.GetBytes(formdata);
postStream.Write(formdataBytes, 0, formdataBytes.Length);
//写入文件内容
if (item.FileContent != null && item.FileContent.Length > 0)
{
using (var stream = item.FileContent)
{
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
{
postStream.Write(buffer, 0, bytesRead);
}
}
}
}
//结尾
var footer = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n");
postStream.Write(footer, 0, footer.Length);
}
else
{
request.ContentType = "application/x-www-form-urlencoded";
}
#endregion
request.ContentLength = postStream.Length;
#region 输入二进制流
if (postStream != null)
{
postStream.Position = 0;
//直接写入流
Stream requestStream = request.GetRequestStream();
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = postStream.Read(buffer, 0, buffer.Length)) != 0)
{
requestStream.Write(buffer, 0, bytesRead);
}
////debug
//postStream.Seek(0, SeekOrigin.Begin);
//StreamReader sr = new StreamReader(postStream);
//var postStr = sr.ReadToEnd();
postStream.Close();//关闭文件访问
}
#endregion
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (cookieContainer != null)
{
response.Cookies = cookieContainer.GetCookies(response.ResponseUri);
}
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader myStreamReader = new StreamReader(responseStream, encoding ?? Encoding.UTF8))
{
string retString = myStreamReader.ReadToEnd();
return retString;
}
}
}
// 压缩JSON字符串
public static string CompressJson(string json)
{
var jsonObject = JToken.Parse(json);
return jsonObject.ToString(Newtonsoft.Json.Formatting.None);
}
// 格式化JSON字符串
public static string FormatJson(string json)
{
var jsonObject = JToken.Parse(json);
return jsonObject.ToString(Newtonsoft.Json.Formatting.Indented);
}
#endregion
#region 窗体事件
private void MainForm_Load(object sender, EventArgs e)
{
panelRight.Visible = false;
}
private void btnShowTools_Click(object sender, EventArgs e)
{
panelRight.Visible = !panelRight.Visible;
}
#region HttpRequest
/// <summary>
/// 请求
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRequest_Click(object sender, EventArgs e)
{
if (cbxMethod.Text.Trim().ToUpper() == "POST")
{
requestPost();
}
else if (cbxMethod.Text.Trim().ToUpper() == "GET")
{
requestGet();
}
}
/// <summary>
/// Json格式化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnJson_Click(object sender, EventArgs e)
{
try
{
txtRequest.Text = FormatJson(txtRequest.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
try
{
txtResponse.Text = FormatJson(txtResponse.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// Json压缩
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCompressJson_Click(object sender, EventArgs e)
{
try
{
txtRequest.Text = CompressJson(txtRequest.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
try
{
txtResponse.Text = CompressJson(txtResponse.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#region SQLite
private void btnCreateDB_Click(object sender, EventArgs e)
{
try
{
var createSql = "CREATE TABLE IF NOT EXISTS Users(Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Age INTEGER);";
var insertSql = "INSERT INTO Users (Name, Age) VALUES ('wangxinyu', 45);";
var querySql = "select * from users;";
var updateSql = "UPDATE Users SET Name='王磊', Age=18 WHERE Id=3;";
var deleteSql = "delete from Users where id=3";
SQLiteHelper sQLite = new SQLiteHelper();
//创建表
var insertInt = sQLite.InsertData(insertSql);
var dt = sQLite.QueryDataTable(querySql);
var updateInt = sQLite.UpdateData(updateSql);
dt = sQLite.QueryDataTable(querySql);
var deleteInt = sQLite.DeleteData(deleteSql);
dt = sQLite.QueryDataTable(querySql);
var createInt = sQLite.CreateTable(createSql);
dt = sQLite.QueryDataTable(querySql);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#endregion
/// <summary>
/// AES加密
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_encrypt_Click(object sender, EventArgs e)
{
EncryptHelper encryptHelper = new EncryptHelper();
txtResponse.Text = encryptHelper.Encrypt(txtRequest.Text.Trim());
}
/// <summary>
/// 解密AES
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_decrypt_Click(object sender, EventArgs e)
{
EncryptHelper encryptHelper = new EncryptHelper();
//txtResponse.Text = encryptHelper.Decrypt(txtRequest.Text.Trim());
txtResponse.Text = encryptHelper.DesDecrypt(txtRequest.Text.Trim(), txtAESKey.Text.Trim());
}
private void btnCompress_Click(object sender, EventArgs e)
{
try
{
var compressStr = EncryptHelper.Compress(txtRequest.Text.Trim());
txtResponse.Text = compressStr;
}
catch (Exception ex)
{
MessageBox.Show("压缩失败" + ex.Message);
}
}
private void btnDeCompress_Click(object sender, EventArgs e)
{
try
{
var deCompressStr = EncryptHelper.Decompress(txtRequest.Text.Trim());
txtResponse.Text = deCompressStr;
}
catch (Exception ex)
{
MessageBox.Show("解压缩失败," + ex.Message);
}
}
private void panelRight_Paint(object sender, PaintEventArgs e)
{
}
/// <summary>
/// 加密压缩Base64
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDes3GzipBase64_Click(object sender, EventArgs e)
{
try
{
//var str = GzipHelper.EncryptData(txtRequest.Text.Trim(),txtAESKey.Text.Trim());
//var zip = GzipHelper.Compress(str);
var ss = GzipHelper.TripleDESEncryptAndGizpReturnBase64(txtRequest.Text.Trim(), txtAESKey.Text.Trim());
txtResponse.Text = ss;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 解压解密base64
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDeDes3GzipBase64_Click(object sender, EventArgs e)
{
try
{
var ss = GzipHelper.DeTripleDESEncryptAndGizpReturnBase64(txtRequest.Text.Trim(), txtAESKey.Text.Trim());
txtResponse.Text = ss;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnDistance_Click(object sender, EventArgs e)
{
PointDistanceForm distanceForm = new PointDistanceForm();
distanceForm.ShowDialog();
}
/// <summary>
/// 调用生成二维码窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCreateQR_Click(object sender, EventArgs e)
{
QRCodeForm qRCodeForm = new QRCodeForm();
qRCodeForm.ShowDialog();
}
private void btnSHA256_Click(object sender, EventArgs e)
{
SHA256Form qRCodeForm = new SHA256Form();
qRCodeForm.ShowDialog();
}
/// <summary>
/// pdf打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPdfPrint_Click(object sender, EventArgs e)
{
PdfDocument doc = new PdfDocument();
doc.PrintSettings.PrinterName = "Microsoft XPS Document Writer";
doc.LoadFromFile("1.pdf");
//使用默认打印机打印文档所有页面
doc.Print();
}
}
public class FormItemModel
{
/// <summary>
/// 表单键,request["key"]
/// </summary>
public string Key { set; get; }
/// <summary>
/// 表单值,上传文件时忽略,request["key"].value
/// </summary>
public string Value { set; get; }
/// <summary>
/// 是否是文件
/// </summary>
public bool IsFile
{
get
{
if (FileContent == null || FileContent.Length == 0)
return false;
if (FileContent != null && FileContent.Length > 0 && string.IsNullOrWhiteSpace(FileName))
throw new Exception("上传文件时 FileName 属性值不能为空");
return true;
}
}
/// <summary>
/// 上传的文件名
/// </summary>
public string FileName { set; get; }
/// <summary>
/// 上传的文件内容
/// </summary>
public Stream FileContent { set; get; }
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/fysz007/http-request-tool.git
[email protected]:fysz007/http-request-tool.git
fysz007
http-request-tool
httpRequestTool
master

搜索帮助