增加TLS兼容
This commit is contained in:
parent
dda0aa0aa2
commit
f2d00d0fa9
@ -355,30 +355,44 @@ namespace FlyDockTool
|
||||
|
||||
public static string PostMoths(string url, string param)
|
||||
{
|
||||
string strURL = url;
|
||||
HttpWebRequest request;
|
||||
request = (HttpWebRequest)WebRequest.Create(strURL);
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/json;charset=UTF-8";
|
||||
string paraUrlCoded = param;
|
||||
byte[] payload;
|
||||
payload = Encoding.UTF8.GetBytes(paraUrlCoded);
|
||||
request.ContentLength = payload.Length;
|
||||
Stream writer = request.GetRequestStream();
|
||||
writer.Write(payload, 0, payload.Length);
|
||||
writer.Close();
|
||||
System.Net.HttpWebResponse response;
|
||||
response = (System.Net.HttpWebResponse)request.GetResponse();
|
||||
System.IO.Stream s;
|
||||
s = response.GetResponseStream();
|
||||
string StrDate = "";
|
||||
string strValue = "";
|
||||
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
|
||||
while ((StrDate = Reader.ReadLine()) != null)
|
||||
try
|
||||
{
|
||||
strValue += StrDate + "\r\n";
|
||||
string strURL = url;
|
||||
HttpWebRequest request;
|
||||
request = (HttpWebRequest)WebRequest.Create(strURL);
|
||||
request.Method = "POST";
|
||||
request.ContentType = "application/json;charset=UTF-8";
|
||||
string paraUrlCoded = param;
|
||||
byte[] payload;
|
||||
payload = Encoding.UTF8.GetBytes(paraUrlCoded);
|
||||
request.ContentLength = payload.Length;
|
||||
Stream writer = request.GetRequestStream();
|
||||
writer.Write(payload, 0, payload.Length);
|
||||
writer.Close();
|
||||
System.Net.HttpWebResponse response;
|
||||
response = (System.Net.HttpWebResponse)request.GetResponse();
|
||||
System.IO.Stream s;
|
||||
s = response.GetResponseStream();
|
||||
string StrDate = "";
|
||||
string strValue = "";
|
||||
StreamReader Reader = new StreamReader(s, Encoding.UTF8);
|
||||
while ((StrDate = Reader.ReadLine()) != null)
|
||||
{
|
||||
strValue += StrDate + "\r\n";
|
||||
}
|
||||
return strValue;
|
||||
}
|
||||
return strValue;
|
||||
catch (WebException ex)
|
||||
{
|
||||
MessageBox.Show("网络请求失败: " + ex.Message + "\\n状态: " + ex.Status);
|
||||
return "";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("其他错误: " + ex.Message);
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
2
mainForm.Designer.cs
generated
2
mainForm.Designer.cs
generated
@ -200,7 +200,7 @@
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "mainForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "福乐云软硬件数据对接工具V1.1(2025042501)";
|
||||
this.Text = "福乐云软硬件数据对接工具V1.1(2025050701)";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.mainForm_FormClosing);
|
||||
this.Load += new System.EventHandler(this.Form1_Load);
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
|
||||
19
mainForm.cs
19
mainForm.cs
@ -24,20 +24,25 @@ namespace FlyDockTool
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
//兼容TLS
|
||||
System.Net.ServicePointManager.SecurityProtocol =
|
||||
System.Net.SecurityProtocolType.Ssl3 |
|
||||
System.Net.SecurityProtocolType.Tls |
|
||||
(System.Net.SecurityProtocolType)768 | // Tls11
|
||||
(System.Net.SecurityProtocolType)3072; // Tls12
|
||||
|
||||
string CurrentDevice= ConfigurationManager.AppSettings["CurrentDevice"];
|
||||
string CurrentDevice = ConfigurationManager.AppSettings["CurrentDevice"];
|
||||
apiOptions.CurrentDevice = CurrentDevice;
|
||||
apiOptions.MacAddress = ConfigurationManager.AppSettings[CurrentDevice].Split(',')[0];
|
||||
apiOptions.MachineCode = ConfigurationManager.AppSettings[CurrentDevice].Split(',')[1];
|
||||
apiOptions.MachineID = ConfigurationManager.AppSettings[CurrentDevice].Split(',')[2];
|
||||
lb_currentDeviceInfo.Text = CurrentDevice;
|
||||
//////测试代码 测试完毕后注释调一下两行代码
|
||||
// string resultDataStr = File.ReadAllText(@"D:\工作\接受数据工具 list\生化URIT-8460.txt", Encoding.GetEncoding("GB18030"));
|
||||
// deviceAnalysis.CreateInstance().deviceAnalysisOption(resultDataStr);
|
||||
btn_start_or_stop_Click(null,null);//启动数据接收
|
||||
// string resultDataStr = File.ReadAllText(@"D:\工作\接受数据工具 list\生化URIT-8460.txt", Encoding.GetEncoding("GB18030"));
|
||||
// deviceAnalysis.CreateInstance().deviceAnalysisOption(resultDataStr);
|
||||
btn_start_or_stop_Click(null, null);//启动数据接收
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -137,7 +142,7 @@ namespace FlyDockTool
|
||||
if (bmm.code == 200)
|
||||
{
|
||||
List<deviceInfo> diList = JsonConvert.DeserializeObject<List<deviceInfo>>(bmm.data.ToString());
|
||||
string showStr= "计算机名称(MacAddress):" + diList[0].MacAddress+"\r\n";
|
||||
string showStr = "计算机名称(MacAddress):" + diList[0].MacAddress + "\r\n";
|
||||
showStr += "设备型号(MachineCode):" + diList[0].MachineCode + "\r\n";
|
||||
showStr += "设备编号(MachineID):" + diList[0].MachineID + "\r\n";
|
||||
MessageBox.Show(showStr);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user